smwikipedia
smwikipedia

Reputation: 64221

How does a browser establish connection with a web server on 80 port? Details?

(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

  1. Browser choose a random local available port, say 5555, and initiate a connection to server's port 80. So on client, the socketfd_client should represent an IP connection like (1.1.1.1:5555, 9.9.9.9:80, TCP).

  2. 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, the socketfd_server should 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?

Upvotes: 2

Views: 3223

Answers (1)

user207421
user207421

Reputation: 310957

Browser choose a random local available port, say 5555

No. The operating system does that: specifically, the TCP part of the network stack.

and initiate a connection to server's port 80. So on client, the socketfd_client should represent an IP connection like (1.1.1.1:5555, 9.9.9.9:80, TCP).

Correct.

Server calls accept() on its port 80 and identified the connection request from client.

Correct.

Then server picks a random local available port, say 8888

No.

to fulfill that connection request.

No.

So on server, the socketfd_server should represent an IP connection like (1.1.1.1:5555, 9.9.9.9:8888, TCP).

No. The connection at both ends is represented by {1.1.1.1:5555, 9.9.9.9:80}. There is no new port at the server end.

My question is:

If my above understanding is correct

It isn't.

socektfd_client and socketfd_server have different server port.

No.

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?

Never.

Upvotes: 5

Related Questions