Connect to multiple servers from the same C client socket

I have one client that is trying to connect to my main server using socket s1. The client should continue to try to connect to the main server using s1, but at the same time connect and continue to send β€œtrying” messages to my secondary server. Is it a good idea to create 2 sockets, reuse the port and create 2 bindings for these 2 sockets or are there better ways to do this? This is the client side and using sockets C. Thank you.

+2
source share
3 answers

If your program is a client of several servers, use one socket per server. You do not need bind for the client socket at all, just connect .

+5
source

I think you are using a TCP socket (right?). Therefore, one connector is required for connection. Then using the port is not so important, because your application is a client application, which is part of starting the connection. Any outgoing port should be fine.

+1
source

Since you can only call connect(2) once for a stream-oriented socket, you really should use at least two sockets to create two simultaneous connections (or connection attempts).

You do not need to bind(2) anything on client ports, except in strange cases. (I think of the Sunmapper RPC daemon, but luckily it has been almost ten years since I took care of the portmapper daemons. Also rlogin needs to bind(2) as a client using the host authentication method, which was horrible.)

+1
source

All Articles