PDA

View Full Version : UDP Networking




CylonGlitch
Oct 19, 2009, 01:59 PM
Anyone have a decent example of doing UDP networking? I have been trying to get this all up and running but have been struggling with it. I understand the UDP interface, but how to establish the connection, I'm not getting it.



chown33
Oct 19, 2009, 02:08 PM
In what programming language?

And UDP doesn't have connections, at least not in the sense that TCP does. UDP sends a datagram to a target consisting of an IP address and port number. No "connection" is involved.

CylonGlitch
Oct 19, 2009, 02:25 PM
In what programming language?

And UDP doesn't have connections, at least not in the sense that TCP does. UDP sends a datagram to a target consisting of an IP address and port number. No "connection" is involved.

Right, there are no sockets per say; but there is the virtual connection between the two devices because they are expecting packets between the two. This is done in XCode3 and Objective-C.

Cromulent
Oct 19, 2009, 02:31 PM
Basically you readfrom() on the receiver and sendto() on the sender.

You must handle everything else manually as UDP does not guarantee the order of packets in the same way as TCP does. You also need to handle lost packets as UDP does not ensure that packets actually reach there destination.

I don't know if Apple have any nice Cocoa wrappers for UDP networking but I have a feeling they don't. If that is so then you need to read up on BSD sockets and look at the C API man pages for the functions I posted above. That should give you a decent starting point to work from.

chown33
Oct 19, 2009, 02:55 PM
Get AsyncUDPSocket:
http://code.google.com/p/cocoaasyncsocket/

You can use it as-is, or read its source to see how to do things yourself.

CylonGlitch
Oct 19, 2009, 04:54 PM
Get AsyncUDPSocket:
http://code.google.com/p/cocoaasyncsocket/

You can use it as-is, or read its source to see how to do things yourself.

THANKS! This is exactly what I was looking for! :D