Connecting to multiple servers from a single client socket C

后端 未结 3 704
栀梦
栀梦 2020-12-11 09:07

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 c

相关标签:
3条回答
  • 2020-12-11 09:38

    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.

    0 讨论(0)
  • 2020-12-11 09:39

    Because you can only call connect(2) once per stream-oriented socket, you really must use at least two sockets to make two simultaneous connections (or connection attempts).

    You don't need to bind(2) anything on client ports, except in strange cases. (I'm thinking of the Sun RPC portmapper daemon, but thankfully it's been nearly a decade since I've cared about the portmapper daemon. Also rlogin needed to bind(2) as a client when using the host-authentication method, which was horrible.)

    0 讨论(0)
  • 2020-12-11 09:57

    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.

    0 讨论(0)
提交回复
热议问题