socket未连接优化

This commit is contained in:
kai60
2022-03-29 11:34:55 +08:00
parent 90bcb3e43a
commit 64d5967585
4 changed files with 35 additions and 4 deletions
@@ -29,5 +29,6 @@
- (void)broadCastHotspotConnectCommandWith:(NSString *)ssidName pwd:(NSString *)pwd;
- (void)broadCastRestartCommand;
- (void)broadCastRestCommand;
-(void)closeComplete:(void(^)(void))block;
@end
@@ -24,6 +24,9 @@
@property (nonatomic, strong) NSTimer *loopTimer;
@property (nonatomic, assign) int tag;
@property (nonatomic, copy) void(^closeBlock)(void);
@end
@@ -139,6 +142,16 @@
[self postmsg:@"发送失败"];
}
}
- (void)closeComplete:(void (^)(void))block
{
self.closeBlock = block;
if(self.loopTimer)
{
[self.loopTimer invalidate];
self.loopTimer=nil;
}
[self.clientSocket close];
}
-(BOOL)onUdpSocket:(AsyncUdpSocket *)sock didReceiveData:(NSData *)data withTag:(long)tag fromHost:(NSString *)host port:(UInt16)port
{
@@ -161,6 +174,9 @@
-(void)onUdpSocketDidClose:(AsyncUdpSocket *)sock{
[self postmsg:@"连接关闭"];
if (self.closeBlock) {
self.closeBlock();
}
}