on the server side, I use the socket.accept () method to handle a new connection to the client. when a client connects, the server uses a random port to communicate with the client.
No, unless you open another, meaningless connection from the server to the client, and you will not do this for the reasons of the firewall. The received socket uses the same local port number as the listening socket. Contrary to a few answers and comments here.
Therefore, your question is based on a misconception. No matter what you run out of, and it can be memory, stream handles, socket handles, socket buffer space, processors, processor power, virtual memory, disk space ... these will not be TCP ports.
EDIT Proponents of the new random port theory should explain the following netstat conclusion:
TCP 127.0.0.4:8009 0.0.0.0:0 LISTENING TCP 127.0.0.4:8009 127.0.0.1:53777 ESTABLISHED TCP 127.0.0.4:8009 127.0.0.1:53793 ESTABLISHED TCP 127.0.0.4:8009 127.0.0.1:53794 ESTABLISHED TCP 127.0.0.4:8009 127.0.0.1:53795 ESTABLISHED TCP 127.0.0.4:8009 127.0.0.1:53796 ESTABLISHED TCP 127.0.0.4:8009 127.0.0.1:53798 ESTABLISHED TCP 127.0.0.4:8009 127.0.0.1:53935 ESTABLISHED
and show where RFC 793 talks about placing a new port in the received socket and where in the TCP connect-handshake TCP connection exchange, the new port number is transmitted.
EJP Apr 10 2018-11-14T00: 00Z
source share