Yao
Yao

Reputation: 709

Specify port number in TCP client socket

I am writing an TCP client socket using C/C++. How could I specify certain port number in my client socket? Say the client socket is going to have two connections with the same server, and the second connection should use the same local(client side) port number to connect. How could pass the parameter into my code?

local port number is decided right after connect()? Or is it stored in the sock_new=socket()?

Thanks in advance.

Upvotes: 0

Views: 2339

Answers (1)

user207421
user207421

Reputation: 311028

Say the client socket is going to have two connections with the same server, and the second connection should use the same local(client side) port number to connect.

Not possible. Something about the tuple {source IP, source port, target IP, target port} has to be unique, to identify the connection.

What actual problem are you trying to solve?

Upvotes: 0

Related Questions