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!
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.
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.
You can't send or receive UDP packets from a TCP connection. If you need to send UDP packets, use a UDP connection.
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.
CocoaAsyncSocket is a nice library that contains a class called AsyncUdpSocket
which is an Obj-C wrapper around the lower-level socket API.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With