开发者

Reopen same socket for reuse C++

开发者 https://www.devze.com 2022-12-12 12:10 出处:网络
I am having an application which listens on a particular RPC Port number say 10001 for connection with another device(hardware) using socket programming.

I am having an application which listens on a particular RPC Port number say 10001 for connection with another device(hardware) using socket programming.

Meanwhile the hardware device will be trying to establish connection t开发者_开发问答o my IP and same port number 10001.

So that way my application and the hardware are connected. Now assume i disconnect the network cable from my machine, my application would still be listening on port number 10001, however it wont receive any connection.

Now if i reconnect the network again then is it possible for me to reuse the same socket which i was using earlier for communicaiton with the hardware.

Do i sound confusing

Thanks


Once an established socket connection has been disconnected, you cannot reuse that socket. You must close that socket and allocate a new socket for a new connection.

However, pulling out the network cable on the listening end should not have any effect on the existing listening socket being able to accept new connections once the cable has been put back in. If it is not able to do that, then your OS's socket stack is likely faulty.

0

精彩评论

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