I want to establish a tcp connection from multiple
clients to the server on the same port at the server.
How do I do that?

Sounds like you’re trying to multiplex the connections at your server.  Provided your application can handle more than one client at a time, TCP multiplexing takes care of the networking side of things for you automatically.

Here’s how..

The Application Service

Whether a server can handle multiple clients is partly a function of the software providing the service at the server itself. Not all applications that run at the server and provide a service to clients can handle multiple connections. That is a software programming and configuration issue that depends on the server application itself.  Check the documentation for the server application to see if it is a multi-threaded application or whether it can spawn child processes.

The Network Service

Setting the server’s application issues aside, let’s talk about the network availability side of the problem.   When a client connects to a server using TCP, the client selects a virtual port number for its connection.  This virtual port on the client is called the ‘local port’ number.  The client then opens a connection to the server on the server’s port number.  The server is the destination, so the server’s port number is the destination port.  The server receives a TCP connection request on its virtual port number, checks the source IP address and port number and places that information in a table.  A TCP server can keep track of up to 65,534 ports for each source client.  Why this weird number?  A TCP header has fields for the source and destination port numbers. These two port number fields use two bytes of computer storage or sixteen bits.  The largest decimal number that sixteen bits can represent is 65,534, so the source and destination ports can range from 0-65,534.

So, multiple clients can connect to the server and the networking software (which is separate from the application) at the server will keep track of the connections. However, each connection is independent of the others, so if you’re trying to synchronize all the clients so that they are displaying the same portion of a video stream at the same time, you will need to have video streaming software that takes care of that, or use multicasting.

I have a complete tutorials on TCP, Multiplexing and multicasting in the tutorials section.

Support InetDaemon.Com