tags:

views:

51

answers:

3

Hey SO

Doing a some practice questions for exam tomorrow can't figure out this one

What is the minimum number of socket port(s) required for a TCP server to connect a TCP client for communication?

Surely its just two right? one for the server one for the client, but this seems to obvious. My mates thinks TCP uses two ports at the server end for for data in and one for data out.

thanks in advance

+2  A: 

Typically one port/socket will be open on the server to listen for incoming connections. Once connected, the connection will have its own (different) socket allocated on the server to continue the conversation. So strictly speaking that's one port and two sockets on the server -- and one on the client if you wish to count that.

EDIT: Yes I believe comments below are right -- editing answer above to distinguish between sockets and ports.

Sean Owen
+1 - beat me to it.
Eric Petroelje
The same port number is used on the server side for both listening for new connections and for established connections (you can verify this via the netstat(1) utility). The TCP stack on the server uses the client port number to distinguish between established connections.
Steve Emmerson
Steve Emmerson is right. Under the common BSD-like sockets API, there's two server *sockets* - one listening for new connections, one communicating with the connected client - but still just one server *port*.
caf
+1  A: 

some protocols (like ftp) uses more than one port (one for control and one for data), but TCP in general can use one port at each sides.

Dani
A: 

The answer is two: one port on the server to both listen for new connections and service established ones and one port on the client.

Steve Emmerson