我已经在这个项目上工作了一段时间,想通过远程连接测试一些新功能,但是客户端无法连接(虽然它过去能够连接)。在本地一切正常。目前我无法移植,所以我正在使用 hamachi。我试过用wireshark捕获hamachi网络流量,客户端请求确实到达了,但服务器没有收到它们。
任何帮助是极大的赞赏。
代码(省略了错误检查以使代码更具可读性):
客户:
addrinfo ADDRESSINFO, *CLIENTINFO=NULL;
ZeroMemory(&ADDRESSINFO, sizeof(ADDRESSINFO));
ADDRESSINFO.ai_family = AF_INET;
ADDRESSINFO.ai_socktype = SOCK_STREAM;
ADDRESSINFO.ai_protocol = IPPROTO_TCP;
ConnectSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
getaddrinfo(strIP.c_str(), strPort.c_str(), &ADDRESSINFO, &CLIENTINFO);
connect(ConnectSocket, CLIENTINFO->ai_addr, CLIENTINFO->ai_addrlen);
freeaddrinfo(CLIENTINFO);
服务器:
addrinfo ADDRESSINFO, *SERVERINFO=NULL;
ZeroMemory(&ADDRESSINFO, sizeof(ADDRESSINFO));
ADDRESSINFO.ai_family = AF_INET;
ADDRESSINFO.ai_socktype = SOCK_STREAM;
ADDRESSINFO.ai_protocol = IPPROTO_TCP;
getaddrinfo(SERVER_IP, SERVER_PORT, &ADDRESSINFO, &SERVERINFO);
ListenSocket = socket(SERVERINFO->ai_family, SERVERINFO->ai_socktype, SERVERINFO->ai_protocol);
ConnectionSocket = socket(SERVERINFO->ai_family, SERVERINFO->ai_socktype, SERVERINFO->ai_protocol);
bind(ListenSocket, SERVERINFO->ai_addr, SERVERINFO->ai_addrlen);
freeaddrinfo(SERVERINFO);
listen( ListenSocket, SOMAXCONN )
while(true)
{
if(ConnectionSocket = accept(ListenSocket, NULL, NULL))
{
//do stuff
}
}