(This question is inspired by a response to this thread: How WebSocket server handles multiple incoming connection requests?)
My understanding is this way:
Assume client IP = 1.1.1.1, server IP = 9.9.9.9
Browser choose a random local available port, say 5555, and initiate a connection to server's port 80. So on client, the
socketfd_clientshould represent an IP connection like(1.1.1.1:5555, 9.9.9.9:80, TCP).Server calls
accept()on its port 80 and identified the connection request from client. Then server picks a random local available port, say 8888, to fulfill that connection request. So on server, thesocketfd_servershould represent an IP connection like(1.1.1.1:5555, 9.9.9.9:8888, TCP).
My question is:
If my above understanding is correct, socektfd_client and socketfd_server have different server port. Client has 80 while server has 8888. How could the communication be carried out? I think client should change to use the server port 8888 as well, but when and how?