CocoaAsyncSocket 使用时的出现的错误

CocoaAsyncSocket 使用时的出现的错误_第1张图片

1.错误码57和错误码32

Error Domain=NSPOSIXErrorDomain Code=57"Socket is not connected" UserInfo={NSLocalizedDescription=Socket isnot connected}

send error: Error Domain=NSPOSIXErrorDomain Code=32 "Broken pipe"

UserInfo={NSLocalizedDescription=Broken pipe}

解决办法:重新初始化socket

- (void)onUdpSocket:(AsyncUdpSocket*)sock didNotReceiveDataWithTag:(long)tag dueToError:(NSError*)error {

NSLog(@"receive error:%@ ",error.description);

//receive error: Error Domain=NSPOSIXErrorDomain Code=57 "Socket is not connected" UserInfo={NSLocaliz

if(error.code==57) {

NSLog(@"sendSocket = %@;;; recSocket = %@;;; sock = %@",self.sendSocket,self.recSocket,sock);

self.isConnect=NO;

self.currentMojing=nil;

[self.mojingIPsList removeAllObjects];

self.count=self.mojingIPsList.count;

[self.recSocket close];

self.recSocket=nil;

[self.sendSocket close];

self.sendSocket=nil;

[self setup];

}

}

- (void)setup{

self.sendSocket= [[AsyncUdpSocket alloc]init];

self.sendSocket.delegate=self;

self.recSocket= [[AsyncUdpSocket alloc]init];

self.recSocket.delegate=self;

NSError* error =nil;

//设置其可以接收广播

//[self.recSocket enableBroadcast:YES error:&error];

//接收时只bind端口

if(![self.recSocketbindToPort:SERIVE_RECEIVE_PORTerror:&error]) {

NSLog(@"bind faile");

return;

}

//加入组播

[self.recSocket  joinMulticastGroup:SERIVE_MulticastGroup_IP  error:nil];

//只会接受一次

[self.recSocket receiveWithTimeout:-1tag:0];

//[self.recSocket receiveOnce:&error];

}

你可能感兴趣的:(CocoaAsyncSocket 使用时的出现的错误)