Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 545
ingh.am Avatar asked Nov 09 '10 21:11

ingh.am


People also ask

Can you use Send with UDP?

UDP sockets can be connected or unconnected - in the first case send should be used and in the second sendto . This does not affect the protocol used, i.e. it still is unreliable UDP. It only affects where the destination is taken from: from the socket or given as argument.

How do I get UDP packets?

To receive packets from all the sending hosts, specify the remote IP address as 0.0. 0.0 . Match the port number specified in the Local IP Port parameter with the remote port number of the sending host.

Can you send UDP over TCP?

You can't send or receive UDP packets from a TCP connection. If you need to send UDP packets, use a UDP connection.

Can UDP packets be sent out of order?

UDP Traffic: Out-of-order packets can also be caused by UDP traffic. This issue occurs primarily due to stateless connections and the lack of flow control mechanisms that exist within UDP protocol.


1 Answers

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

like image 72
Daniel Dickison Avatar answered Oct 12 '22 23:10

Daniel Dickison