Receive no data with GCDAsyncUdpSocket

107 views
Skip to first unread message

Tim A.

unread,
Jun 5, 2019, 10:28:58 AM6/5/19
to CocoaAsyncSocket
Hello,

I have built an UDP socket with (GCDAsyncUdpSocket) and don't get any answers through the other side.
With Wireshark I see the answers (on the machine), but not in my code. The sending side is ok and works.

The delegate method udpsocket(didReceiveData) is never triggered and I get no result.
See my code in attachment. I have a class (SocketSender) which sends some dummy data and the other class (SocketReceiver) receives the answers from the other machine.

Could someone tell me why I don't receive the data in the delegate method? IMHO the delegate method ** should be triggered. Is that right?
Or is something other totally wrong from my side? In Wireshark I see that the messages are correct sent.
I also see in the debug navigator the bytes are outgoing and incoming on my machine (see picture in attachment).

** func udpSocket(didReceiveData: Data, fromAddress: Data, withFilterContext: Any?) {
        print("data incoming incoming incoming")
}

debug_provider.png


SocketSender.swift
SocketReceiver.swift

Tim A.

unread,
Jun 7, 2019, 3:55:16 AM6/7/19
to CocoaAsyncSocket
Could someone help me?

Sean McBride

unread,
Jun 7, 2019, 5:22:44 PM6/7/19
to cocoaasy...@googlegroups.com, Tim A.
On Wed, 5 Jun 2019 07:28:58 -0700, Tim A. said:

>The delegate method udpsocket(didReceiveData) is never triggered and I get
>no result.

Did you put breakpoints at all the places where CocoaAsyncSocket invokes the delegate? Presumably you won't hit any of them. Then move each breakpoint up a few lines and see if you get that far. You have all the code, you should be able to debug more to find the condition that results in the delegate not being invoked.


Tim A.

unread,
Jun 11, 2019, 4:16:53 AM6/11/19
to CocoaAsyncSocket
Okay ... I will try it.

Tim A.

unread,
Jun 11, 2019, 7:49:07 AM6/11/19
to CocoaAsyncSocket

 Presumably you won't hit any of them
IMHO I get no events in this delegate.

Did you put breakpoints at all the places where CocoaAsyncSocket invokes the delegate? 
Did it and checked the results for socket.bind() and socket.beginReceiving().
Both methods returned a YES as result. So I would say all things are fine.

Arno Gramatke

unread,
Jun 11, 2019, 8:32:36 AM6/11/19
to cocoaasy...@googlegroups.com
I think your issue is, that when you create the listener, it listens on a arbitrary port (because you set its port to 0) and the remote end sends the values back to the original port.

And when you tried to set it to the same port as the sender, you probably couldn’t bind to it, because it was already in use?

Why don’t you just use one instance to send and receive and bind that to the port of your liking?

--
You received this message because you are subscribed to the Google Groups "CocoaAsyncSocket" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cocoaasyncsock...@googlegroups.com.
To post to this group, send email to cocoaasy...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cocoaasyncsocket/889c4373-ddfa-4243-bbc1-e56369639e03%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Tim A.

unread,
Jun 11, 2019, 9:53:52 AM6/11/19
to CocoaAsyncSocket
I think your issue is, that when you create the listener, it listens on a arbitrary port (because you set its port to 0) and the remote end sends the values back to the original port.
I tried the same with a specific port (e.g. 47111) but without success. 

Why don’t you just use one instance to send and receive and bind that to the port of your liking?
I've also tested this scenario, but also without success. See my new code in attachment. 
 
Am Dienstag, 11. Juni 2019 14:32:36 UTC+2 schrieb Arno Gramatke:
I think your issue is, that when you create the listener, it listens on a arbitrary port (because you set its port to 0) and the remote end sends the values back to the original port.

And when you tried to set it to the same port as the sender, you probably couldn’t bind to it, because it was already in use?

Why don’t you just use one instance to send and receive and bind that to the port of your liking?
Am 11.06.2019 um 13:49 schrieb Tim A. <nms....@gmail.com>:


 Presumably you won't hit any of them
IMHO I get no events in this delegate.

Did you put breakpoints at all the places where CocoaAsyncSocket invokes the delegate? 
Did it and checked the results for socket.bind() and socket.beginReceiving().
Both methods returned a YES as result. So I would say all things are fine.

Am Dienstag, 11. Juni 2019 10:16:53 UTC+2 schrieb Tim A.:
Okay ... I will try it.

Am Freitag, 7. Juni 2019 23:22:44 UTC+2 schrieb seanm:
On Wed, 5 Jun 2019 07:28:58 -0700, Tim A. said:

>The delegate method udpsocket(didReceiveData) is never triggered and I get
>no result.

Did you put breakpoints at all the places where CocoaAsyncSocket invokes the delegate?  Presumably you won't hit any of them.  Then move each breakpoint up a few lines and see if you get that far.  You have all the code, you should be able to debug more to find the condition that results in the delegate not being invoked.



--
You received this message because you are subscribed to the Google Groups "CocoaAsyncSocket" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cocoaasy...@googlegroups.com.

Tim A.

unread,
Jun 11, 2019, 9:55:44 AM6/11/19
to CocoaAsyncSocket
And the new code here
UdpSocket.swift

Tim A.

unread,
Jun 11, 2019, 9:56:27 AM6/11/19
to CocoaAsyncSocket
And the new code here

Is there something totally wrong what I did?

Arno Gramatke

unread,
Jun 11, 2019, 9:59:25 AM6/11/19
to cocoaasy...@googlegroups.com
Best would be to send your whole project.

To unsubscribe from this group and stop receiving emails from it, send an email to cocoaasyncsock...@googlegroups.com.

To post to this group, send email to cocoaasy...@googlegroups.com.

Tim A.

unread,
Jun 11, 2019, 10:17:43 AM6/11/19
to CocoaAsyncSocket
I can't send the whole project, because there are some internal things with closed source.
But I trigger the static function from the socket class in a UI class (from a button listener).

Is that totally wrong?


Am Dienstag, 11. Juni 2019 15:59:25 UTC+2 schrieb Arno Gramatke:
Best would be to send your whole project.
To unsubscribe from this group and stop receiving emails from it, send an email to cocoaasyncsocket+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages