AsyncUdpSocket how to use receive

前端 未结 4 1928
甜味超标
甜味超标 2021-01-04 18:23

I am trying to get a program for iPhone running on the simulator. My problem is with receiving UDP data. I use asyncUdpSocket. If I make a socket and use sendData:(NSD

4条回答
  •  粉色の甜心
    2021-01-04 18:38

    I'm new with Objective C (so bear with my ignorance of it), but I have been able to get AsyncUdpSocketDelegate to receive, for the most part. A few things to try/confirm:

    1. Make sure the self class that you are initializing as your socket delegate is the class that you're expecting the callbacks on.

    2. Make sure your class adopts the AsyncUdpSocketDelegate protocol. I'm not sure if this is actually necessary, but it couldn't hurt. In your class header, looks like:

      @interface |your class| : |super class| <|Other protocol(s)|, AsyncUdpSocketDelegate> {

    3. Make sure you have your delegate methods declared in your interface and implementation. The method signature should look like this: - (BOOL)onUdpSocket:(AsyncUdpSocket *)sock didReceiveData:(NSData *)data withTag:(long)tag fromHost:(NSString *)host port:(UInt16)port;

    4. Try calling receiveWithTimeout with a non-zero timeout value. May give you different results.

    5. Use Wireshark to make sure you are in fact receiving UDP data when and where you think you are. I'm not trying to insult your intelligence, but I've spent quite a while trying to track down network code bugs in the past when the issue was actually my network configuration.

提交回复
热议问题