How can I check is a socket is still open?

前端 未结 2 1341
没有蜡笔的小新
没有蜡笔的小新 2021-01-05 08:36

I have a C++ app that uses standard socket calls and I want to know if I can tell if a socket is still open without sending or receiving any data. Is there a reliable

2条回答
  •  無奈伤痛
    2021-01-05 09:22

    A socket being "open" doesn't help you with end-to-end connectivity. The only way to know for sure that you can communicate with the other end is to, well, communicate with the other end.

    In any protocol you design, you should think about implementing this checking behavior. If it's not your protocol, there's sometimes ways to do it sneakily (for example FTP up a very small, useless file to check if the FTP ports are both still open).

提交回复
热议问题