C++ Winsock 10093 error -
i'm trying build server in c++ can accept multiple number of clients. purpose built winsock wrapper , using threading boost communication each clients.
encountered strange problem when trying accept clients, have loop looks this.
int clientid = 0; listensocket = new socket(sockettype::tcp); listensocket->bind(port); listensocket->listen(); while(running) { socket *socket = &listensocket->accept(); mutex.lock(); clients.push_back(new client(socket, clientid)); mutex.unlock(); std::cout << "client id " << clientid << " connected!" << std::endl; std::cout << wsagetlasterror() << std::endl; clientid++; }
now, first client accepts fine , wsagetlasterror() returns 0, after first 1 connected, if dont trying connect keep writing in console 10093, means accept() in loop stoppped blocking , reason wont accept properly. read online error caused not calling wsastartup() did called in socket's constructor , did accept in first time.
10093 wsanotinitialised
, means wsacleanup()
has been called more times wsastartup()
has been called.
based on code have provided, appears socket::accept()
returning socket
instead of socket*
. if so, accept()
creating temporary socket
goes out of scope after socket *socket
assigned. chances socket
destructor calling wsacleanup()
when should not be. calls wsastartup()
, wsacleanup()
must balanced @ times.
Comments
Post a Comment