Sending UDP packets from the iPhone

2019-03-08 00:51发布

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!

2条回答
闹够了就滚
2楼-- · 2019-03-08 01:23

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

查看更多
\"骚年 ilove
3楼-- · 2019-03-08 01:41

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

查看更多
登录 后发表回答