hope you have a nice day. Another socket problem, another day :)
Finally, I got the installed MicroSoft Visual C ++ environment (MSVC ++), as well as the platform SDK, so I can compile winsock applications.
Missed a piece of stuff here. In the ServerSocket :: accept () function, it creates a new ClientSocket instance and sets its socket file descriptor to the one that was accept () ed, I also checked there, and it recognized that the descriptor is really there.
In my ClientSocket :: recv () function, I call (obviously) the recv () function from the winsock library. The problem I'm facing is that the socket descriptor I'm using is recognized by recv () as invalid, but only on the ClientSocket instance on the server side returned from my ServerSocket :: accept (). There is no problem on the client instance of ClientSocket. I inserted some debug statements, the handle is valid.
The strangest bit about this is that if I compile this exact code using MinGW gcc / g ++ on windows, it works fine! It uses only MSVC ++ that this problem occurs.
string ClientSocket::recv(int bufsize) { if (!isConnected()) throw SocketException("Not connected."); cout << "SocketRecv: " << (sockfd == INVALID_SOCKET) << " " << sockfd << endl; vector<char> buffer(bufsize+1, 0); cout << "SocketRecv1: " << (sockfd == INVALID_SOCKET) << " " << sockfd << endl; int ret = ::recv(sockfd, &buffer[0], bufsize, 0); cout << "SocketRecv2: " << (sockfd == INVALID_SOCKET) << " " << sockfd << endl;
Additional information: The socket is in blocking mode, i.e. was not set to non-blocking. I have successfully called WSAStartup (). This happens on the server side, in the ClientSocket instance returned from my ServerSocket :: accept () (yes, I also checked the handle there - that's fine). The client side declares: "WSAECONNRESET (10054)" or "WSAECONNABORTED (10053)."
I can't think of anything else that could be wrong. Worst of all, it works great using MinGW gcc / g ++ for Windows and Linux.
If you want to see the entire library, it is inserted in: (caution: 600+ lines!)
Socket.cxx - http://paste.pocoo.org/show/353725/
Socket.hxx - http://paste.pocoo.org/show/353726/
Thanks!!!
Update . According to the solution for Ben, I now use: void ServerSocket::accept(ClientSocket& sock); and implement as: ClientSocket mysock; server.accept(mysock); ClientSocket mysock; server.accept(mysock);
Thank you very much.