简体   繁体   中英

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.

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM