After reading several tutorials I came up with the following code:
(Using the famous GCDAsyncUdpSocket class)
NSError *error = nil;
if (![mSocket connectToHost:@"192.168.1.111" onPort:9050 error:&error])
{
NSLog(@"Error connecting: %@", [error description]);
}
usleep(100000);
NSString* str = @"teststring";
[mSocket sendData:[str dataUsingEncoding:NSUTF8StringEncoding] toHost:@"192.168.1.111" port:9050 withTimeout:-1 tag:1];
If I run this code on my iPhone everything seems fine (no errors).
But the packet never arrives on my PC.
On my PC a UDP listener is running (alongside with Wireshark). Both devices are on the same network with the same subnet and similar IPs (my PC is 192.168.1.111). Am I doing something wrong? A simple mistake hopefully?
The methods
are for sending messages with unconnected sockets, so you should not call
connectToHost. For a connected host, you can use