title: How to listen on a specific port on iPhone ios4.2?
body: <p>I'm going crazy about my actual project... </p>
  
  <p>I've got a device which is sending data on a specific port. My goal is to detect all this kind of device on that port. 
  Example : I've got 4 this kind of devices on the same network and I would with the iPhone detect all this device. </p>
  
  <p>It works with a JAVA discover tool and now i'm trying to do it on my iPhone. </p>
  
  <p>There are the steps used in the JAVA discover tool  : </p>
  
  <ul>
  <li>Create a DatagramSocket (JAVA)</li>
  <li>Get the broadcast address (255.255.255.255)</li>
  <li>Create DatagramPacket (JAVA)</li>
  <li>Send the packet on the broadcast adresse with the port 30303</li>
  <li>Go in receive mode</li>
  <li>Due to the socket, it get the answers packets</li>
  <li>Extract the ip and the hostname from the device</li>
  </ul>
  
  <p>I tried to repoduce the same steps by using the AsyncUdpSocket class : <a href="http://code.google.com/p/cocoaasyncsocket/" rel="nofollow">http://code.google.com/p/cocoaasyncsocket/</a></p>
  
  <p>And here is the code I tried so far : </p>
  
  <pre><code>NSError *e;
  NSString *d = @"abcd";
  NSData *data = [d dataUsingEncoding:NSUTF8StringEncoding];
  
  
  ssocket = [[AsyncUdpSocket alloc]initWithDelegate:self];
  [ssocket setDelegate:self];
  
  
  
  [ssocket enableBroadcast:YES error:&amp;e];
  
  
  [ssocket connectToHost:@"255.255.255.255" onPort:30303 error:&amp;e];
  
  
  [ssocket sendData:data withTimeout:-1 tag:0];
  
  [ssocket receiveWithTimeout:-1 tag:0];
  </code></pre>
  
  <p>The delegate <code>- (BOOL)onUdpSocket:(AsyncUdpSocket *)sock didReceiveData:(NSData *)data withTag:(long)tag fromHost:(NSString *)host port:(UInt16)port</code>is never called ... </p>
  
  <p>I don't know what is wrong .. Can you please give me your opinions about this subject ? If i'm using the right methodology and see If I did anything wrong ?? </p>
  
  <p>Thank you in advance !! </p>
  
  <p>MoKeS</p>
  
  <p>EDIT :</p>
  
  <p>I used wireshark to sniff the network traffic with the JavaDiscoverTool and my application. 
  In fact the difference between the 2 packets (iphone's and javadiscovertool's) is the Source Port.
  Indeed, on my application, the source port is different than the destination port and I think that is causing the issue. 
  I need to find a way to force the source port on the packet i'm sending ... </p>
  
  <p>Any ideas ? It's on the AsyncUdpSocket class.</p>