title: connect multiple programs to one server with sockets, c
body: <p>I need to make a server and a client to a simple chat. The server must to have threads to keep listening all clients and must send a message received to everyone. The server must have 2 threads to keep listening the socket for new messages and to read the message from keyboard and send it to the server. My problem is: how to make multiple connections to the server? I was thinking in use multiples sockets, one for each client, and the clients would try to connect with each port until some works, but it doesn't give error if the socket already has a connection in a port as I tough. Does someone has some tips? I need to use TCP.</p>
  
  <p>EDIT: My problem isn't in the server, my problem is in the client. What I did (or tried, at least, I'm not sure if it's right) was make the main in the server create a thread to listen a socket. When there is a connection, this thread take care of that socket and the main create another thread to take care of other socket with other port. The problem is: how can I detect in the client that a port is already in use and I need to connect in the socket of the next port?</p>
  
  <p>And sory for the bad English.</p>