onmyway133
onmyway133

Reputation: 48175

Does TCP use another port for sending data?

I heard that for TCP connection, server will listen on 1 port, and use another port for sending data.

For example, web server listen on port 80. Whenever client connects to it, this server will use another port (say 9999) to send data (web content) to client. If multiple clients connect to it, does this server create multiple "another ports" to send data back ?

And does the client uses 2 ports (listening port and sending-data port) as the server does ?

Am I right? I heard many people said that and I can't find any good books or articles about this

Please explain

Upvotes: 6

Views: 7876

Answers (2)

user2002592
user2002592

Reputation: 1

Here is a simple example. When the browser in your laptop sends a request to a web server which listens on port 443, your OS uses an ephemeral port (e.g. tcp/3105) as source port and Port tcp/443 of the web server as the destination port.

Once the web server sends back the response, it will use the source port as tcp/443 and the destination port as tcp/3105.

Here is a link to an AWS documentation. https://docs.aws.amazon.com/vpc/latest/userguide/vpc-network-acls.html

Upvotes: 0

user207421
user207421

Reputation: 311018

I heard that for TCP connection, server will listen on 1 port, and use another port for sending data.

No. The same port is used for both listening and for accepted connections, and the same connection is normally used for both sending and receiving. TCP connections are bidirectional. FTP is an exception to this, as it uses two connections: one for commands and one for data.

For example, web server listen on port 80. Whenever client connects to it, this server will use another port (say 9999) to send data (web content) to client.

No.

If multiple clients connect to it, does this server create multiple "another ports" to send data back ?

No.

And does the client uses 2 ports (listening port and sending-data port) as the server does ?

No.

Am I right?

No.

I heard many people said that

They were all wrong.

and I can't find any good books or articles about this

There aren't any. Only a very bad book or article would say any such thing.

Upvotes: 26

Related Questions