开发者

Multiple TCP connections in C

Can a process open/maintain 2 TCP connections in parallel? [for sending and receiving]. I tried the following scenario :

1) Client connects to server on one port, say 13101.

2) Once it sends, it will wait on another port 13102 to get the ACK.

3) Here Server can handle multiple connections [using select() on same port number].

Now, I am facing 2 problems: 1) Server on receiving data from Client1, it is processing data and for sending the ACK back [to client1], I am preparing a new TCP co开发者_如何学Cnnection [with port 13102] and trying to send data. It fails with "Connection Refused".

2) In order to verify the above problem, I wrote another client2 program that just sends data to port 13102 [to client1, when it is in listening mode]. Still client2 is getting "Connection refused" error.


Yes, you can open lots of sockets! However, you shouldn't need separate sockets for sending and receiving, a TCP socket is bi-directional once it's opened. As for your error, if you're using two machines, there could be a firewall preventing the server from connecting to your client. You might try using telnet to try to connect to the same port.


The error is probably because the client is not listening for an incoming connection. As stated above you can use a single socket for both send and receive.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜