English 中文(简体)
接收UDP包裹的电话问题
原标题:iphone problem receiving UDP packets

使用<代码>sendto()和recv from (,通过UDP向WFI发送一些简单的包装。

我用两部电话和一台模拟器进行抽查,结果为:

Packets sent from phones -> recieved by simulator Packets sent from simulator -> simulator recvfrom remains blocking. Packets sent from phones -> other phone recvfrom remains blocking.

我不敢肯定如何开始分解,因为模拟器/磁盘能够接收包装单,但电话似乎不会收到电文。

稍微例外,我是否需要把我的包裹放在我网络的MTU下? 还是由监督厅或其他一些低级软件处理碎块问题?

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;

(a) 证明书数据为:

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;

发送包裹如下:

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);

包装和包装一样:

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
}
问题回答

我不认为你可以接收数据,而不要让本组织知道,你会再听什么。 即将运入的包裹的港口数量一般与港口号码相对照,以确定包装需要交付的地点。

建造固定港口号(如49153或以任何方式)和在双方使用这种编号。

你提到使用Bonjour,我理解这允许动态地发现网络资源,但我认为这值得尝试。





相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签