I had a problem sending an udp message (broadcast) to the client and receiving a response, but this will be displayed twice. When I test the connection on my PC with the UDP listener, there is only one message.
Maybe someone can give me information on how I can resolve this.
I use the button to start sending a message!
#import "ViewController.h" #import "GCDAsyncUdpSocket.h" @interface ViewController () { long tag; GCDAsyncUdpSocket *udpSocket; } @end @implementation ViewController - (void)setupSocket { udpSocket = [[GCDAsyncUdpSocket alloc] initWithDelegate:self delegateQueue:dispatch_get_main_queue()]; NSError *error = nil; if (![udpSocket bindToPort:1000 error:&error]) { NSLog(@"Error binding: %@", error); return; } if (![udpSocket beginReceiving:&error]) { NSLog(@"Error receiving: %@", error); return; } [udpSocket enableBroadcast:YES error: &error]; NSLog(@"Ready"); } - (void)viewDidLoad { [super viewDidLoad]; if (udpSocket == nil) { [self setupSocket]; } } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning];
Here is the conclusion!
2013-09-11 09:49:00.132 udptest[5145:907] 15 2013-09-11 09:49:08.218 udptest[5145:907] 192.168.2.255 2013-09-11 09:49:08.220 udptest[5145:907] SENT (15): 1,0,1,2 2013-09-11 09:49:08.319 udptest[5145:907] RECV: 0,0,0,0,0,0,0,0 2013-09-11 09:49:08.321 udptest[5145:907] 17 2013-09-11 09:49:08.323 udptest[5145:907] RECV: 0,0,0,0,0,0,0,0 2013-09-11 09:49:08.324 udptest[5145:907] 18
I would really appreciate it if someone could help me.
source share