How to initialize and instance from GCDAsyncUdpSocket

I just need to send a basic message over UDP. I have already given up, and probably I need to use some of the libraries. When I research, there are examples of the AsyncUdpSocket library. I do not know where I can load this class, and in the end I found GCDAsyncUdpSocket . Apparently they have a different constructor, and for this very reason I cannot create an instance of a new object to send an udp message. I know the basics of c lens, and I would appreciate it if someone could show me a short example of how to broadcast a message. the server part, which I have already received, I'm just interested in the client part.

+3
source share
1 answer

First download the GCDAsyncUdpSocket from here . Then you can send packets like:

 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];
+4
source

All Articles