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