--
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/aa30d2e9-c4c5-4e4e-8c56-eee107f80060%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
You received this message because you are subscribed to a topic in the Google Groups "CocoaAsyncSocket" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/cocoaasyncsocket/hV0uhxRsL4I/unsubscribe.
To unsubscribe from this group and all its topics, 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/15C15CA2-1823-4ECD-BFC8-D418FF486602%40gramatke.biz.
To view this discussion on the web visit https://groups.google.com/d/msgid/cocoaasyncsocket/69DF6B26-4FC6-4C09-9777-A9F6DFCD9DFE%40gmail.com.
--
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/6388F392-C94F-4EAD-BEE4-D32E63298A9D%40gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.
To view this discussion on the web visit https://groups.google.com/d/msgid/cocoaasyncsocket/34549A12-483B-44A8-A29E-54C35125FFCF%40gramatke.biz.
For more options, visit https://groups.google.com/groups/opt_out.
<LinkManager.m>
Tobin,from what I can see, you are not binding the socket to a port (as I suggested in my previous mail), but you connect the socket to the remote host. Don’t mix up connecting (=remote) and binding (=local). connectToHost:onPort:error: just connects to the given remote port on the given remote host, but uses a random port on the local machine. If you need to use a specific local port you have to bind the socket before(!) connecting or sending data.In your startUdpClientConnection method insert the following line before the call to connectToHost:onPort:error: and add error checking as appropriate:BOOL whatever = [_gcdUdpSock bindToPort:yourLocalPort error:&err];That should setup your socket to listen on yourLocalPort.
Apart from that I am a little confused by your code. :) Here are the things that got me confused:1) Where do you start receiving? I don’t see a call to beginReceiving? The TCP and UDP variants of GCDAsyncSocket are somewhat different due to the underlying protocol. It looks like you started with a TCP setup and switched to UDP later on but didn’t adopt to the different interface.2) You are mixing TCP and UDP stuff and I don’t see the delegate methods for the UDP part - only TCP delegates are visible in the code you posted. Even when you have done the above you won’t see any incoming data without the appropriate delegate methods. At least implement the following- (void)udpSocket:(GCDAsyncUdpSocket *)sock didReceiveData:(NSData *)data fromAddress:(NSData *)address withFilterContext:(id)filterContext;
3) What are kRepeaterIPAddress and kRepeaterPort? Are these your local address and port or the remote ones? If they are the local ones, why do you connect to them? There is no need to do this. Just use bindToPort.
By the way: your are sending data to _remoteAddress. Using this on a connected4) Sorry for the harsh words, but the TCP parts (especially the comments) don’t look like you really understand what you are doing. It looks like you are just trying to receive arbitrary data without any idea of the underlying protocol. There is a reason why you have to tell GCDAsyncSocket to read data again and again. That might be very annoying in the beginning, but in return you get a very flexible system for handling networking data. Check the general introduction in the GCDAsyncSocket wiki on Github.
5) Why do you work with threading when using GCDAsyncUdpSocket? This should not be necessary as the networking stuff is running asynchronously in its own GCD dispatch queue. If you are worried about processing of the received data, you can also choose a different delegate queue if you like (in your code use use the main queue - you can set this).
For me it looks like you really need to clean up your code. Do you need both TCP and UDP?
Please don’t get me wrong. I made plenty of mistakes myself when I first started using GCDAsyncSocket und GCDAsyncUdpSocket over a year ago. But it’s all in the documentation. You just have to make yourself familiar with it. :)Again, I hope that helps.Arno
To view this discussion on the web visit https://groups.google.com/d/msgid/cocoaasyncsocket/CA4108B9-695B-4742-9644-785BE1E1576A%40gramatke.biz.
To view this discussion on the web visit https://groups.google.com/d/msgid/cocoaasyncsocket/BEB11D85-22D8-4E66-9FA7-E763B8883CAF%40gmail.com.