C++ ServerSocket抛出InvalidArgumentException,但文档未指定原因。为什么?
我正在使用Poco创建一个Web服务器。我在ServerSocket库中遇到错误。下面是重现错误的最小代码C++ ServerSocket抛出InvalidArgumentException,但文档未指定原因。为什么?,c++,serversocket,poco-libraries,C++,Serversocket,Poco Libraries,我正在使用Poco创建一个Web服务器。我在ServerSocket库中遇到错误。下面是重现错误的最小代码 #include <iostream> #include "Poco/Net/ServerSocket.h" #include "Poco/Net/StreamSocket.h" #include "Poco/Net/SocketAddress.h" #define PORT (unsigned short) 3000 int main() { Poco::Net::S
#include <iostream>
#include "Poco/Net/ServerSocket.h"
#include "Poco/Net/StreamSocket.h"
#include "Poco/Net/SocketAddress.h"
#define PORT (unsigned short) 3000
int main()
{
Poco::Net::ServerSocket x;
x.bind(PORT);
Poco::Net::StreamSocket conn;
Poco::Net::SocketAddress clientAddr;
try {
conn = x.acceptConnection(clientAddr);
}
catch (Poco::InvalidArgumentException e) {
printf("Oh no! %s\n", e.displayText().c_str());
return 1;
}
printf("Huzzah!");
return 0;
}
我试图查看[文档]以了解错误,但它甚至没有将此函数列为抛出此错误。我还尝试了函数的无参数版本,但它仍然抛出此异常,这向我表明,抛出错误的不是函数,而是子函数。为什么?我怎样才能修复它,或者解决它呢?正如WhozCraig所说,问题不在于将它置于倾听状态。代码应该是
#include <iostream>
#include "Poco/Net/ServerSocket.h"
#include "Poco/Net/StreamSocket.h"
#include "Poco/Net/SocketAddress.h"
#define PORT (unsigned short) 3000
int main()
{
Poco::Net::ServerSocket x;
x.bind(PORT);
x.listen(1); // or number of acceptable connections
Poco::Net::StreamSocket conn;
Poco::Net::SocketAddress clientAddr;
try {
conn = x.acceptConnection(clientAddr);
}
catch (const Poco::InvalidArgumentException& e) {
printf("Oh no! %s\n", e.displayText().c_str());
return 1;
}
printf("Huzzah!");
return 0;
}
不相关但更改捕获Poco::InvalidArgumentException e{以捕获常量Poco::InvalidArgumentException&e{为什么?我如何修复它,或者如何解决它?-POCO没有完整的源代码吗?为什么不调试到该函数中,看看哪一行引发异常?绑定套接字,但似乎从未将其置于侦听模式。服务器通常是bind+listen,在accept上循环。绑定时,从不侦听,然后接受,这是无效的因为你从来没有听过。我的前妻经常指责我,世界太小了。你为什么不把错误信息贴在这里?