4

I'm almost completely done with and iOS client for my REST service. The only thing I'm missing is the ability for the client to listen on the network for a UDP broadcast that receives the host display name and base URL for uploads. There could be multiple servers on the network broadcasting and waiting for uploads.

Asynchronous is preferred. The servers will be displayed to the user as the device discovers them and I want the user to be able to select a server at any point in time.

The broadcaster is sending to 255.255.255.255 and does not expect any data back.

I am a beginner in objective c so something simple and easy to use is best.

Gray
  • 7,050
  • 2
  • 29
  • 52
nick
  • 2,833
  • 3
  • 34
  • 61

1 Answers1

4

I recommend looking at CocoaAsyncSocket. It can handle UDP sockets well. I haven't tried listening to a broadcast with it, but it's probably your best bet.

Rob Napier
  • 286,113
  • 34
  • 456
  • 610
  • 1
    When I try to make a new instance of the GCDAsyncSocket it tells me this: Undefined symbols for architecture i386: "_OBJC_CLASS_$_GCDAsyncUdpSocket", referenced from: objc-class-ref in ImageShareViewController.o ld: symbol(s) not found for architecture i386 clang: error: linker command failed with exit code 1 (use -v to see invocation) I'm not sure what that means other than it doesn't want to run on the iPhone simulator because it doesn't like the architecture. Any ideas? – nick Mar 13 '12 at 19:30
  • This means you're not linking the GCDAsyncUdpSocket code. It may be because you're linking a static library that only has iOS objects, or you may not be linking the library at all, or you may not be compiling the source as part of this target. – Rob Napier Mar 13 '12 at 19:33
  • To get it to work I had to disable ARC. Are there any significant risks to doing so that I should be aware of? – nick Mar 13 '12 at 19:57
  • ARC can safely be turned on and off on a per-file basis. If the GCDAsync code is not ARC compliant, then you can turn ARC off for those files. – Rob Napier Mar 13 '12 at 20:00
  • I've got it working and didn't have to do anything special to receive the UDP broadcasts. Thanks – nick Mar 13 '12 at 20:05
  • @RobNapier: do you know if there is a CocoaAsyncSocket java implementation or something similar to use in Android? Thanks. – VansFannel Jun 07 '12 at 08:54
  • CocoaAsyncSocket has no java implementation. – Rob Napier Jun 07 '12 at 11:19