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.


In reply to Re: Socket programming with 1 server-Multiple client. by ikegami
in thread Socket programming with 1 server-Multiple client. by hari9

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.