Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specifying port number on client side

Tags:

c

unix

sockets

How can I make sure that my client uses a particular port to connect to server in a typical server client program. Like in server side we are using a port number in bind system call and then listen on that particular port, is there any way we can specify the port number on the client side and uses the same port to connect to server. Server = 3456 , Client = 7834 ( I want to specify this port number so that client uses 7834 for connection). I am trying in C and Unix platform.

like image 925
Prak Avatar asked Dec 16 '22 07:12

Prak


1 Answers

You do this on the client side exactly as you do it on the server side - using bind(). It's just that the client calls connect() after bind() instead of calling listen().

Note that you will only be able to run one instance of the client on each machine if you do this, and your server might see a different client port anyway if there are network middleboxes using address translation between the client and server.

like image 160
caf Avatar answered Dec 29 '22 00:12

caf