Note that there are some explanatory texts on larger screens.

plurals
  1. POiphone problem receiving UDP packets
    text
    copied!<p>I'm using <code>sendto()</code> and <code>recvfrom()</code> to send some simple packets via UDP over WiFI.</p> <p>I've tried using two phones, and a simulator, the results I'm getting are:</p> <p>Packets sent from phones -> recieved by simulator Packets sent from simulator -> simulator recvfrom remains blocking. Packets sent from phones -> other phone recvfrom remains blocking.</p> <p>I'm not sure how to start debugging this one, since the simulator/mac is able to receive the the packets, but the phones don't appear to be getting the message.</p> <p>A slight aside, do I need to keep my packets below the MTU for my network? Or is fragmentation handled by the OS or some other lower level software?</p> <p>UPDATE: I forgot to include the packet size and structure. I'm transmitting:</p> <pre><code>typedef struct PacketForTransmission { int32_t packetTypeIdentifier; char data[64]; // size to fit my biggest struct } PacketForTransmission; </code></pre> <p>of which the char data[64] is:</p> <pre><code>typedef struct PacketHeader{ uint32_t identifier; uint32_t datatype; } PacketHeader; typedef struct BasePacket{ PacketHeader header; int32_t cardValue; char sendingDeviceID[41]; //dont forget to save room for the NULL terminator! } BasePacket; typedef struct PositionPacket{ BasePacket basePacket; int32_t x; int32_t y; } PositionPacket; </code></pre> <p>sending packet is like:</p> <pre><code>PositionPacket packet; bzero(&amp;packet, sizeof(packet)); //fill packet with it's associated data PacketForTransmission transmissionPacket; transmissionPacket.packetTypeIdentifier = kPositionPacketType; memcpy(&amp;transmissionPacket.data, (void*)&amp;packet, sizeof(packet)); //put the PositionPacket into data[64] size_t sendResult = sendto(_socket, &amp;transmissionPacket, sizeof(transmissionPacket), 0, [address bytes], [address length]); NSLog(@"packet sent of size: %i", sendResult); </code></pre> <p>and recieving packets is like:</p> <pre><code>while(1){ char dataBuffer[8192]; struct sockaddr addr; socklen_t socklen = sizeof(addr); ssize_t len = recvfrom(_socket, dataBuffer, sizeof(dataBuffer), 0, &amp;addr, &amp;socklen); //continues blocking here NSLog(@"packet recieved of length: %i", len); //do some more stuff } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload