我正在创建一个套接字。它很容易第一次工作然后我停止套接字并重新生成它给我错误
class MainServer{
private:
SOCKET soo;
public:
// I have Basically Created Server Socket in this Function
// And passed it
SOCKET socket_control_mob(){
struct sockaddr_in server;
WSADATA wsa;
printf("\nInitialising Winsock...");
if (WSAStartup(MAKEWORD(2, 2), &wsa) != 0)
{
printf("Failed. Error Code : %d", WSAGetLastError());
MessageBox(NULL, TEXT("Failed"), L"Failed", NULL);
soo = NULL;
return soo;
}
printf("Initialised.\n");
//MessageBox(NULL, TEXT("Initialised"), L"Simple Message", NULL);
//Create a socket
if ((soo = socket(AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET)
{
printf("Could not create socket : %d", WSAGetLastError());
MessageBox(NULL, TEXT("Socket Not Created1"), L"Failed", NULL);
soo = NULL;
return soo;
}
printf("Socket created.\n");
//Prepare the sockaddr_in structure
server.sin_family = AF_INET;
server.sin_addr.s_addr = INADDR_ANY;
server.sin_port = htons(8890);
//Bind
if (bind(soo, (struct sockaddr *)&server, sizeof(server)) == SOCKET_ERROR)
{
printf("Bind failed with error code : %d", WSAGetLastError());
MessageBox(NULL, TEXT("Binding Error"), L"Failed", NULL);
soo = NULL;
return soo;
}
puts("Bind done");
//MessageBox(NULL, TEXT("Bind Done"), L"Simple Message", NULL);
return soo;
}
bool server_close_socket(){
closesocket(soo);
WSACleanup();
return true;
}
};
我通过调用
创建了一个套接字MainServer s;
s.socket_control_mob()
我已经通过
停止了套接字s.server_close_socket()
停止后不会创建套接字
答案 0 :(得分:0)
您正在错误处理套接字,甚至是WinSock库本身。尝试更像这样的东西:
NoAnnotationError {message: "Cannot resolve all parameters for CustomHttpServic…ake sure they all have valid type or annotations.", stack: $
## _onError ##
TypeError: Cannot read property 'get' of undefined
at angular2.dev.js:19620
at Zone.run (angular2.dev.js:138)
at Zone.run (angular2.dev.js:10644)
at NgZone.run (angular2.dev.js:10607)
at ApplicationRef_.bootstrap (angular2.dev.js:19615)
at Object.commonBootstrap (angular2.dev.js:26650)
at Object.bootstrap (angular2.dev.js:27475)
at Object.<anonymous> (app.ts:23)
at app.ts:23
at SystemJSLoader.__exec (system.src.js:1384)
Uncaught TypeError: Cannot read property 'get' of undefined
答案 1 :(得分:-1)
这是众所周知的事情。您创建的套接字处于FIN_WAIT状态。要避免此问题,请在重新运行程序前等待2分钟,按照“graceful shutdown”协议或为套接字提供SO_REUSEADDR选项。