报错信息:Error Domain=GCDAsyncUdpSocketErrorDomain Code=1 "Must bind socket before you can receive data. You can do this explicitly via bind, or implicitly via connect or by sending data." UserInfo={NSLocalizedDescription=Must bind socket before you can receive data. You can do this explicitly via bind, or implicitly via connect or by sending data.}
错误分析:
两部手机,在利用socket进行客户端与服务端通讯时.客户端转服务端的时候没有Close掉客户端.一直占用着端口.
所以在创建服务端的时候,调用[_udpSocket bindToPort:5432 error:&error];
就会报以上错误.
解决方案:
在清理客户端的时候增加一句[_asyncUdpSoket close];
// 客户端退出
- (void)clientDisconnect {
ZLLog(@"%s",__func__);
[_timer invalidate];
_timer = nil;
[_asyncUdpSoket close]; // 关键代码
_asyncUdpSoket = nil;
_UDPClient = nil;
}