Does anyone know how the delegate method for receiving UDP data in CocoaAsyncSockets work when it comes to fetching the source address? Specifically the method
-(void)udpSocket:(GCDAsyncUdpSocket *)sock didReceiveData:(NSData *)data fromAddress:(NSData *)address withFilterContext:(id)filterContext
The address comes back as NSData*
but interpreting it using NSUTF8StringEncoding
returns null
and NSASCIIStringEncoding
returns a bunch of garbled characters. How is it supposed to be interpreted?
Figured out how to do it, the data is in the form of a
struct sockaddr_in*
. After importing<arpa/inet.h>
you can do the following: