Multiple Socket Connections

Posted by BSchlinker on Stack Overflow See other posts from Stack Overflow or by BSchlinker
Published on 2010-06-06T06:18:47Z Indexed on 2010/06/06 6:22 UTC
Read the original article Hit count: 371

I need to write a server which accepts connections from multiple client machines, maintains track of connected clients and sends individual clients data as necessary. Sometimes, all clients may be contacted at once with the same message, other times, it may be one individual client or a group of clients.

Since I need confirmation that the clients received the information and don't want to build an ACK structure for a UDP connection, I decided to use a TCP streaming method. However, I've been struggling to understand how to maintain multiple connections and keep them idle.

I seem to have three options. Use a fork for each incoming connection to create a separate child process, use pthread_create to create an entire new thread for each process, or use select() to wait on all open socket IDs for a connection.

Recommendations as to how to attack this? I've begun working with pthreads but since performance will likely not be an issue, multicore processing is not necessary and perhaps there is a simpler way.

© Stack Overflow or respective owner

Related posts about c++

Related posts about sockets