AsyncUdpSocket missing data

116 views
Skip to first unread message

Pieter-Jan Deraedt

unread,
Sep 20, 2013, 8:07:46 AM9/20/13
to cocoaasy...@googlegroups.com
Hi all,

For this application I need to connect to a "Tibbo" (more information here: http://tibbo.com/).
When I send a broadcast "X", all Tibbo's will respond with the IP address/port they are reachable on.

So to start my project, I first send a broadcast "X" like this:

    NSString *bcHost = @"255.255.255.255";
    NSString *anyHost = @"0.0.0.0";
   
    int UDP_SOCKET_PORT = 65535;
    int DISCOVERY_PORT  = 6003;

    udpSocket = [[AsyncUdpSocket alloc] initWithDelegate:self];
    [udpSocket bindToAddress:anyHost port:DISCOVERY_PORT error:nil];
    [udpSocket enableBroadcast:YES error:nil];
    [udpSocket receiveWithTimeout:4 tag:UDPBROADCAST_MSG];
    [udpSocket sendData:[@"X" dataUsingEncoding:NSASCIIStringEncoding] toHost:bcHost port:UDP_SOCKET_PORT withTimeout:-1 tag:UDPBROADCAST_MSG];
    [udpSocket closeAfterSendingAndReceiving];


AsyncUdpSocket sometimes fetches the response, sometimes it doesn't. When I test in the lab with 3 tibbo's in it, sometimes it receives the answer from 1 or 2 tibbo's, sometimes from all of them... When I use wireshark to check, I ALWAYS see all tibbo's answering. So the tibbo's are doing what is asked from them, but AsyncUdpSocket seem to miss these responses. These responses come in within 0.03 second. I have to say that the problem doesn't only occur when multiple tibbo's are responding, even with only 1 tibbo responding, the data is often not coming in the didReceiveData delegate method.

Anyone has an idea what could cause this issue?

Leonid Usov

unread,
Oct 7, 2016, 3:00:10 PM10/7/16
to CocoaAsyncSocket
Hi Peter-Jan!

It's so cool you have posted here as I am also having problems with async socket and tibbo!
Until recently I have thought the problem is somewhere in the AsyncSocket such that it misses some UDP responses. I my case I am missing a data response, not a broadcast, like you - I am polling an external device multiple times per second and quite often I don't receive the notification although I see the packet on the tcpdump.

BUT today I have noticed something important. The response from Tibbo is sent to 255.255.255.255 address, not to my host's ip address. So it is not recognized by the bound socket. This explains why i "miss" the socket. 

Can you please double check your responses if they actually have the correct destination address?

see below, the Tibbo suddenly responds to "all hosts", and usually it happens when another parallel process checks the Tibbo device status via the command port

21:57:40.862095 IP 192.168.14.184.63724 > 192.168.14.161.1001: UDP, length 1
21:57:41.059681 IP 192.168.14.161.1001 > 192.168.14.184.63724: UDP, length 9
21:57:41.162382 IP 192.168.14.184.63724 > 192.168.14.161.1001: UDP, length 1
21:57:41.305894 IP 192.168.14.184.53098 > 192.168.14.161.65535: UDP, length 5
21:57:41.309790 IP 192.168.14.161.1001 > 255.255.255.255.63724: UDP, length 9
21:57:41.411056 IP 192.168.14.161.65535 > 192.168.14.184.53098: UDP, length 58
21:57:42.066347 IP 192.168.14.184.63724 > 192.168.14.161.1001: UDP, length 1
21:57:42.220419 IP 192.168.14.161.1001 > 192.168.14.184.63724: UDP, length 9
21:57:42.382730 IP 192.168.14.184.63724 > 192.168.14.161.1001: UDP, length 1



пʼятниця, 20 вересня 2013 р. 15:07:46 UTC+3 користувач Pieter-Jan Deraedt написав:
Reply all
Reply to author
Forward
0 new messages