热点连接优化

This commit is contained in:
kai60
2022-03-27 22:08:21 +08:00
parent 9a5fe717a2
commit 90bcb3e43a
6 changed files with 62 additions and 26 deletions
@@ -49,6 +49,9 @@
NSError *error;
//本地接收端口
[self.clientSocket bindToPort:bindPort error:&error];
if (error) {
[self postmsg: error.localizedDescription];
}
}
return self;
}
@@ -130,7 +133,11 @@
self.tag = 0;
[self.clientSocket receiveWithTimeout:-1 tag:self.tag];
[self.clientSocket sendData:data toHost:hostS port:port withTimeout:-1 tag:self.tag];
BOOL send= [self.clientSocket sendData:data toHost:hostS port:port withTimeout:-1 tag:self.tag];
if (!send)
{
[self postmsg:@"发送失败"];
}
}
-(BOOL)onUdpSocket:(AsyncUdpSocket *)sock didReceiveData:(NSData *)data withTag:(long)tag fromHost:(NSString *)host port:(UInt16)port
@@ -153,26 +160,30 @@
}
-(void)onUdpSocketDidClose:(AsyncUdpSocket *)sock{
NSLog(@"关闭");
[self postmsg:@"连接关闭"];
}
-(void)onUdpSocket:(AsyncUdpSocket *)sock didSendDataWithTag:(long)tag{
NSLog(@"didSendData");
[self postmsg:@"指令发送"];
}
-(void)onUdpSocket:(AsyncUdpSocket *)sock didNotReceiveDataWithTag:(long)tag dueToError:(NSError *)error{
NSLog(@"dueToError%@",error);
[self postmsg:@"Socket连接失败"];
[self postmsg:[NSString stringWithFormat:@"Socket连接失败:%@",error.localizedDescription]];
}
-(void)dealloc{
[self postmsg:@"dealloc"];
[self.clientSocket close];
}
- (void)postmsg:(NSString *)msg {