報(bào)錯(cuò)信息: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.}
錯(cuò)誤分析:
兩部手機(jī),在利用socket進(jìn)行客戶端與服務(wù)端通訊時(shí).客戶端轉(zhuǎn)服務(wù)端的時(shí)候沒有Close掉客戶端.一直占用著端口.
所以在創(chuàng)建服務(wù)端的時(shí)候,調(diào)用[_udpSocket bindToPort:5432 error:&error];
就會(huì)報(bào)以上錯(cuò)誤.
解決方案:
在清理客戶端的時(shí)候增加一句[_asyncUdpSoket close];
// 客戶端退出
- (void)clientDisconnect {
ZLLog(@"%s",__func__);
[_timer invalidate];
_timer = nil;
[_asyncUdpSoket close]; // 關(guān)鍵代碼
_asyncUdpSoket = nil;
_UDPClient = nil;
}