Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The server and client in localhost don't use the same port.</p> <p>As a connected Tcp connection,</p> <p>To server,source port is A and destination port is B.</p> <p>To client,source port is B and destination port is A.</p> <p>A is set by bind() in server, and is known to all clinets; B is usually assigned by clinets' kernel, and is known to server when the server's accept() returns.</p> <p>In details:</p> <p>In tcp,the server's port is set by bind() which lets us specify a port number, an IP address, both, or neither, but it is rare for a TCP server to let the kernel choose an ephemeral port Afterwards, server listen() the port and IP address.</p> <p>and client uses connect() whose socket address structure must contain the IP address and port number of the server. <strong>the kernel will choose both an ephemeral port and the source IP address if necessary.</strong> Anyway, it can't be the port your server using.</p> <p>That's to say, the ports of a server and a clinet in the same computer is not the same.</p> <p><em>For example</em>, when simple C/S programs running in a localhost, typing netstat -t in terminal,and you will get:</p> <pre><code>Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 localhost:41742 localhost:9877 ESTABLISHED tcp 0 0 localhost:9877 localhost:41742 ESTABLISHED </code></pre> <p>the prots is obviously different.</p> <p>If you force the client to use the same port of your the one server is using on local by bind(), the bind() will return -1 as a error.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload