socket使用结束时调用close方法

This commit is contained in:
xuemh 2018-08-17 06:58:50 +08:00
parent 28be9a9ea6
commit 6782887878
2 changed files with 6 additions and 5 deletions

View File

@ -43,11 +43,6 @@
UITapGestureRecognizer *fiveTapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(test)]; UITapGestureRecognizer *fiveTapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(test)];
fiveTapGesture.numberOfTapsRequired = 5; fiveTapGesture.numberOfTapsRequired = 5;
[self.containerView addGestureRecognizer:fiveTapGesture]; [self.containerView addGestureRecognizer:fiveTapGesture];
IFishUDPHelperBackMsgModel *model = [IFishUDPHelperBackMsgModel new];
model.result = @"01";
model.senderMacAddress = @"123456778";
[self udpHelperCommandExecutedSuccess:model];
} }
- (void)test { - (void)test {
@ -155,6 +150,7 @@
[self appendTrakContent:@"=================收到设备答复==================="]; [self appendTrakContent:@"=================收到设备答复==================="];
[self appendTrakContent:[NSString stringWithFormat:@"答复状态码:%@", backModel.result]]; [self appendTrakContent:[NSString stringWithFormat:@"答复状态码:%@", backModel.result]];
[self appendTrakContent:[NSString stringWithFormat:@"答复Mac地址:%@", backModel.senderMacAddress]]; [self appendTrakContent:[NSString stringWithFormat:@"答复Mac地址:%@", backModel.senderMacAddress]];
[[IFishHotpotUDPHelper sharedInstance] broadCastRestartCommand];
[self bindDeviceWithSsid:backModel.senderMacAddress]; [self bindDeviceWithSsid:backModel.senderMacAddress];
} }

View File

@ -154,6 +154,7 @@
AppDelegate *app =(AppDelegate*)[UIApplication sharedApplication].delegate; AppDelegate *app =(AppDelegate*)[UIApplication sharedApplication].delegate;
[app.window makeToast:[NSString stringWithFormat:@"收到答复:%@", result]]; [app.window makeToast:[NSString stringWithFormat:@"收到答复:%@", result]];
} }
[self.clientSocket close];
[self.loopTimer invalidate]; [self.loopTimer invalidate];
return YES; return YES;
@ -161,6 +162,7 @@
-(void)onUdpSocketDidClose:(AsyncUdpSocket *)sock{ -(void)onUdpSocketDidClose:(AsyncUdpSocket *)sock{
[self.clientSocket close];
[self.loopTimer invalidate]; [self.loopTimer invalidate];
NSLog(@"关闭"); NSLog(@"关闭");
} }
@ -176,12 +178,15 @@
NSLog(@"dueToError%@",error); NSLog(@"dueToError%@",error);
[self postmsg:error.localizedDescription]; [self postmsg:error.localizedDescription];
[self.clientSocket close];
[self.loopTimer invalidate]; [self.loopTimer invalidate];
} }
-(void)dealloc{ -(void)dealloc{
[self.clientSocket close];
[self.loopTimer invalidate]; [self.loopTimer invalidate];
} }