iphone problem receiving UDP packets
- by SooDesuNe
I'm using sendto() and recvfrom() to send some simple packets via UDP over WiFI.
I've tried using two phones, and a simulator, the results I'm getting are:
Packets sent from phones - recieved by simulator
Packets sent from simulator - simulator recvfrom remains blocking.
Packets sent from phones - other phone recvfrom remains blocking.
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.
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?
UPDATE:
I forgot to include the packet size and structure. I'm transmitting:
typedef struct PacketForTransmission {
int32_t packetTypeIdentifier;
char data[64]; // size to fit my biggest struct
} PacketForTransmission;
of which the char data[64] is:
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;
sending packet is like:
PositionPacket packet;
bzero(&packet, sizeof(packet));
//fill packet with it's associated data
PacketForTransmission transmissionPacket;
transmissionPacket.packetTypeIdentifier = kPositionPacketType;
memcpy(&transmissionPacket.data, (void*)&packet, sizeof(packet)); //put the PositionPacket into data[64]
size_t sendResult = sendto(_socket, &transmissionPacket, sizeof(transmissionPacket), 0, [address bytes], [address length]);
NSLog(@"packet sent of size: %i", sendResult);
and recieving packets is like:
while(1){
char dataBuffer[8192];
struct sockaddr addr;
socklen_t socklen = sizeof(addr);
ssize_t len = recvfrom(_socket, dataBuffer, sizeof(dataBuffer), 0, &addr, &socklen); //continues blocking here
NSLog(@"packet recieved of length: %i", len);
//do some more stuff
}