objective-c - iOS UDP socket 通讯 使用GCDAsyncUdpSocket 服务器无法接受到消息?求大神解决
本文介绍了objective-c - iOS UDP socket 通讯 使用GCDAsyncUdpSocket 服务器无法接受到消息?求大神解决的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
现在我要使用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
解决方案
感觉没哪里有错,但就是收不到数据这是什么原因
这篇关于objective-c - iOS UDP socket 通讯 使用GCDAsyncUdpSocket 服务器无法接受到消息?求大神解决的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文