Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connecting to multiple servers from a single client socket C

Tags:

c

sockets

I have a single client that is trying to connect to my main server using socket s1. The client needs to keep trying to connect to main server with s1, but at the same time connect and keep sending "trying" messages to my secondary server. Is it a good idea to create 2 sockets,reuse port and create 2 binds for those 2 sockets or there are better ways to achieve this? This is a client side and using C sockets. Thanks.

like image 687
user629034 Avatar asked Oct 23 '25 02:10

user629034


2 Answers

If your program is a client to multiple servers, use one socket per server. You don't need bind for a client socket at all, just connect.

like image 92
Fred Foo Avatar answered Oct 25 '25 18:10

Fred Foo


I think you are using TCP socket( aren't you?). So one socket for connection is needed. Then reuse port is not so important because your application is a client application, which is the part the start the connection. Any outbound port should be ok.

like image 36
Heisenbug Avatar answered Oct 25 '25 18:10

Heisenbug



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!