How can I reconnect a socket after a broken pipe?

前端 未结 2 569
栀梦
栀梦 2020-12-19 05:35

The program connects to a server, and when the connection is closed by the server, if I try to reconnect it says: socket.error: [Errno 9] Bad file descriptor

相关标签:
2条回答
  • 2020-12-19 06:04

    If the file descriptor is bad then you will need to release that resource and create a new socket. This will get you a new file descriptor.

    If the connection terminated abnormally, you will have to wait for the server to close it's end of the connection before you can reconnect. I would just poll it frequently (but not too frequently) to see if you can reestablish a connection with your new socket.

    How often do you get the bad pipe error?

    0 讨论(0)
  • 2020-12-19 06:08

    Assuming this is a connection oriented socket:

    No. You have to close the old one and create a new socket,

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