Menu
  • HOME
  • TAGS

C++ I/O Multiplexed server closes connections prematurely

c++,sockets,select,stdvector,berkeley-sockets

Your clientsV member should be a std::vector<base_socket*> (i.e. keeping the pointer references). You have a chance that a temporary client_t object is being created and destroyed during push_back if it needs to relocate existing elements to a different area (See Why does vector::push_back and emplace_back call value_type::constructor twice?). When this...

Generation of unique IP-port using bind(0)

c++,sockets,berkeley-sockets

bind() expects a sockaddr* not a sockaddr_in*: bind(sfd, (struct sockaddr *) &my_addr, sizeof(my_addr)) Other than that, I don't see any other errors. Binding to port 0 is the correct way to bind to a random available port. If bind() and listen() do not report a failure then netstat should see...