Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to init and instance from GCDAsyncUdpSocket

I just need to send a basic message with via UDP. I already gave up and I guess I have to use some of the libraries out there. As I research there are examples of the AsyncUdpSocket library. I don't know where I can download that class and I end up finding GCDAsyncUdpSocket. Aparently they have a different constructor and that is the reason why I am not able to instantiate a new object in order to send a udp message. I know the basics of objective c and I will appreciate if someone can show me a short example of how to broadcast a message. the server part I already got I am just interested in the client part.

like image 867
Tono Nam Avatar asked Sep 08 '26 21:09

Tono Nam


1 Answers

First download GCDAsyncUdpSocket from here. Then you may send packets as:

 GCDAsyncUdpSocket *udpSocket ; // create this first part as a global variable
 udpSocket = [[GCDAsyncUdpSocket alloc] initWithDelegate:self delegateQueue:dispatch_get_main_queue()];

 NSData *data = [[NSString stringWithFormat:@"Hello World"] dataUsingEncoding:NSUTF8StringEncoding];

[udpSocket sendData:data toHost:@"192.168.10.111" port:550 withTimeout:-1 tag:1];
like image 171
Tono Nam Avatar answered Sep 11 '26 11:09

Tono Nam



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!