Natesan Prabhakaran wrote:
My thought was to create a port for Client A and a different port for Client B on the server and then somehow pass the message through.
Server always listen on the same port. Client will connect to the server with different Ip address in the same port number.
-Prabhakaran
Hmm, not really sure what you are trying to say...
A client connected to one IP address will stick with that IP address.
And the same is true for the port.
Example:
ssh daemon (sshd), the server is listening on port 22 on all IP addresses available on one machine.
From the netstat output we can see that sshd is listening on port
22 on all IPv4 and IPv6 interfaces of this machine.
The first column is the protocol in use. In our case it is Transmission Control Protocol (TCP).
The second column is the depth of the receive queue. Zero is good, no backlog.
The third column is the send queue depth.
Column four is the IP address and port the server is listening on.
An IPv4 address of 0.0.0.0 and an IPv6 address of ::: means "any interface that is up".
Columns five is IP address and port the client is connecting from. And in this
case where no one is connected, basically the addresses our server will accept.
The last column shows the status on the socket. It says LISTENING,
pretty obvious, the server is listening.
Now let's see what it looks like when a client connects.
The netstat output tells us:
sshd has a connection accepted on 192.168.1.80 port 22a remote client is connected from 192.168.1.65 port 59235even though something in sshd is dealing with the client conected to port 22, the server is still listening on port 22
So what does it look like with more than one client connected?
now we have two more clients connected.
One more from 192.168.1.65 (same IP address) from port 58132.and another from 206.169.85.86 (different IP) from port 59446
So, what happens inside sshd?
The socket sshd is listening on, is equivalent to our ServerSocket
in
Java. The socket used by sshd for handling client connections
is our Socket.
Depending on your operating system implementation, these might
be different sockets (internally, and hidden from us) and thus,
different streams.
If your OS supports the system call select() it will be the same
socket with multiple streams associated.
However, we get different streams for listening and each individual
client.
This allows us to handle client connections in the client handler
while the server loop continues listening.
Hope this made it a bit more clear
Matt