Little problem with AsyncUdpSocket receiving data after connecting to broadcast instead of server

前端 未结 4 1140
天命终不由人
天命终不由人 2021-02-15 22:58

I have a problem with AsyncUdpSocket.

I used to connect to a server, send some data and get some response. Now since I do not know the actual address of the server I had

4条回答
  •  臣服心动
    2021-02-15 23:25

    You are 'connecting' to the host. Per the Unix socket FAQ, this means you'll only get UDP packets back that have a source IP address of 255.255.255.255. Connecting establishes a 1-to-1 relationship for UDP, such that received packets whose source addresses differ from the connected address will be filtered.

    If you don't connect (you'll have to change your send line to target the broadcast address), it should work. You'll send toHost:bcHost -- and then your receive should get all packets destined for its port.

提交回复
热议问题