现在我要使用udp socket进行聊天通讯,代码如下
**_udpSocket = [[GCDAsyncUdpSocket alloc]initWithDelegate:self delegateQueue:dispatch_get_main_queue()];
NSError * error = nil;
[_udpSocket bindToPort:udpPort error:&error];
[_udpSocket enableBroadcast:YES error:&error];
if (error) {
NSLog(@"error:%@",error);
}else {
[_udpSocket beginReceiving:&error];
}
[self sendMessage:textField.text andType:@0];
NSString * ipAddress = [self deviceIPAdress];
MessageInfo *info = [[MessageInfo alloc]init];
info.sendId = @"201312260000014064";
info.targetId = @"201312260000014063";
info.info = @"你好";
info.device = @"iOS";
NSData * sendData = [self returnDataWithObject:info];
[_udpSocket sendData:sendData toHost:@"10.10.2.73" port:udpPort withTimeout:-1 tag:0];
textField.text = nil;
return YES;
通讯具体过程是我把要发送的数据封装成类 然后通过流的形式发送到服务器,GCDAsyncUdpSocket应该会自己处理流(不确定),现在服务器收不到消息,服务器Host是10.10.2.73 端口是8888
感觉没哪里有错,但就是收不到数据这是什么原因