Server connections
I have written a DLL which allows me to set up a server or a client using TCP. The server sets up a socket that it listens on and every time an incoming connection is detected (using select()) it accepts the socket and places the new socket in an array of "x" number of sockets. The amount of sockets the server can hold is set when the server is created.
The problem I have is that once a client has connected and then disconnected, the server will not accept any more connections. The client appears to "connect" to the server, but the server does not recognise an incoming connection and no data can be transferred. The only way I have found to get round this is to restart the server.
I have created the listening socket like this:
sListen = socket(AF_INET, SOCK_STREAM, 0);
if (sListen == INVALID_SOCKET) {
return WSAGetLastError();
}
if (bind(sListen, (struct sockaddr*)&local, sizeof(local)) == SOCKET_ERROR) {
return WSAGetLastError();
}
if (listen(sListen, 5) == SOCKET_ERROR) {
return WSAGetLastError();
}
if (ioctlsocket(sListen, FIONBIO, &ioctl_opt) == SOCKET_ERROR) {
return WSAGetLastError();
}
FD_SET(sListen, &fdsRead);
Another thread is then created which contains a permanant loop that calls select() to check the listen socket for incoming connections and checks already connected sockets for incoming data.
i = select(0, &fdsRead, &fdsWrite, &fdsExcept, &tval);
I''ve tried everything that I can think of now. I tried shutting down and recreating the listening socket after a connection, but that didn''t help. Any ideas?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement