title: CocoaAsyncSocket UDP Simple Server & Client
body: <p>I'm trying to start off and create a simple UDP server and client using CocoaASyncSocket. I've pretty much replicated the code in the examples from <a href="https://github.com/robbiehanson/CocoaAsyncSocket/tree/master/Examples/GCD" rel="nofollow">here</a></p>
  
  <p><strong>UPDATE:</strong> </p>
  
  <p>I've tried running the provided examples but they don't seem to work with the host address + port that I provided. What would I fill in for those (on the client end) if my client + server are on the same wifi?</p>
  
  <p><strong>My Server:</strong></p>
  
  <pre><code>-(void)startServer{
      udpSocket = [[GCDAsyncUdpSocket alloc] initWithDelegate:self delegateQueue:dispatch_get_main_queue()];
  
      NSError *error = nil;
  
      if (![udpSocket bindToPort:PORT error:&amp;error])
      {
          NSLog(@"Error starting server (bind): %@", error);
          return;
      }
      if (![udpSocket beginReceiving:&amp;error])
      {
          [udpSocket close];
          NSLog(@"Error starting server (recv): %@", error);
          return;
      }
  
      NSLog(@"Udp Echo server started on %@:%i",[udpSocket localHost_IPv4],[udpSocket localPort]);
  
      isRunning = YES;
  
  }
  </code></pre>
  
  <p><strong>My Client:</strong></p>
  
  <pre><code>-(void)setupSocket{
      udpSocket = [[GCDAsyncUdpSocket alloc] initWithDelegate:self delegateQueue:dispatch_get_main_queue()];
  
      NSError *error = nil;
  
  
      if (![udpSocket bindToPort:HOST_PORT error:&amp;error])
      {
          NSLog(@"Error binding: %@", error);
          return;
      }
      if (![udpSocket beginReceiving:&amp;error])
      {
          [udpSocket close];
          NSLog(@"Error receiving: %@", error);
          return;
      }
  
      NSLog(@"ready");
  }
  
  - (IBAction)send:(id)sender
  {
  
      NSString *msg = @"testerrrr";
  
      NSData *data = [msg dataUsingEncoding:NSUTF8StringEncoding];
      [udpSocket sendData:data toHost:HOST_IP port:HOST_PORT withTimeout:-1 tag:0];
      NSLog(@"sent message to server");
  }
  </code></pre>
  
  <p>I don't believe that my issue is in the initialization of the server or the socket, but perhaps in what my chosen IP + PORT's are. Right now I am running the server on iOS simulator and the client on a real device. When sending data from the device, I can see that packets are going out, but none are being received by the server. </p>
  
  <p>I have it set up to bind port 1234, and that the client sends it to the server's address which I got from "whatismyip.com". I also tried reversing the roles, but still no success. </p>
  
  <p>Additionally, when I tried sending data to itself (server -> server for example), that worked, but between the two no luck! </p>
  
  <p>This seems like a pretty straightforward task but haven't been able to get it to work. Appreciate the help!</p>