Determine if server is listening when using udp

前端 未结 3 486
我在风中等你
我在风中等你 2021-01-24 22:49

The setting: I want to write a point-to-point Connection class that, when used, does not differentiate between server and client. The first host wh

相关标签:
3条回答
  • 2021-01-24 23:08

    With UDP, the communication model is akin to a message in a bottle: you know you sent it, but there's no way to know if anyone ever received it.

    You need to manually establish a communication protocol to determine if the remote party is listening (e.g. have them send a "Yes, I 'm here" response). This would require both endpoints to accept UDP datagrams.

    0 讨论(0)
  • 2021-01-24 23:11

    As Jon and Andrew said you can't see if a listener is open, but you can implement a ping/pong protocol. Send a ping first time you connect if no pong back then set this up like a server.
    If you got pong back then that's your server.

    0 讨论(0)
  • 2021-01-24 23:17

    I don't think you can check for a listening server, short of sending a packet and waiting to see if you get a reply.

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