hari9 has asked for the wisdom of the Perl Monks concerning the following question:

Gm Monks, To start with I'm using a 1 server- 2 client system(SocketProgramming). The server is a linux machine, and I'm working on windows machine. I used a socket program for a server-client pair in the server machine (logging into putty.) Client 2- I use the same client code on my machine(windows). My question is, how would I make client 2 communicate with the server(which is on linux machine)i.e what should be the socket details for client 2. In short: For server1(linux machine): LocalHost='localhost',LocalPort=9000; for client1(linux machine) PeerAddress='localhost',LocalPort=9000, for client2(Windows machine) PeerAddress='(IAM NOT SURE WHAT SHOULD COME HERE)',LocalPort=9000, Thanks in advance.
  • Comment on Socket programming with 1 server-Multiple client.

Replies are listed 'Best First'.
Re: Socket programming with 1 server-Multiple client.
by ikegami (Patriarch) on Jul 19, 2010 at 16:40 UTC
    Both clients connect to the same address:port. A TCP connection is identified by a pair of address:port, so client1:port1-server:port is a different connection than client2:port2-server:port.
    # If you want to accept connections from any network interface server: LocalPort=>9000, Listen=>SOMAXCONN # If you want to only accept connections from the local machine server: LocalHost=>'localhost', LocalPort=>9000, Listen=>SOMAXCONN client1: PeerAddress=>'server', PeerPort=>9000 client2: PeerAddress=>'server', PeerPort=>9000

    Update: Oops, I thought you were asking about PeerPort. The PeerAddress is the DNS name or IP address of the server. The IP address can be obtained from /sbin/ifconfig on linux.

    $ /sbin/ifconfig eth1 Link encap:Ethernet ... # For an Ethernet adapter inet addr:192.168.3.58 ... # Its IP address ... lo Link encap:Local Loopback # For machine to contact itself inet addr:127.0.0.1 # Its IP address ...

    Note that 192.168.* is reserved for private networks, which means my machine isn't really on the internet. A NAT gateway links us up. If you want to run a server behind a NAT gateway, outside connectors must connect to the gateway's external address, and the gateway must be setup to forward those connections to your server's machine.