ingh.am
ingh.am

Reputation: 26822

Sending UDP packets from the iPhone

Does anyone have any good tutorials on sending UDP packets from the iPhone SDK?

EDIT:

Was actually really easy to do this...

RTFM!

After including AsyncUdpSocket just add this in header:

AsyncUdpSocket *socket;

And in main:

NSData *data = ... 
[socket sendData:data toHost:@"192.168.x.x" port:5002 withTimeout:-1 tag:1];

When testing don't forget to allow UDP communication on your server firewall!

Upvotes: 18

Views: 28741

Answers (2)

Daniel Dickison
Daniel Dickison

Reputation: 21882

CocoaAsyncSocket is a nice library that contains a class called AsyncUdpSocket which is an Obj-C wrapper around the lower-level socket API.

Upvotes: 17

Donald
Donald

Reputation: 1738

You can use the CFNetwork framwork to create a UDP socket with CFSocket. Here is the CFSocket reference.

Upvotes: 2

Related Questions