This commit is contained in:
xuemh
2018-08-27 21:34:34 +08:00
parent eb993bbe01
commit ee03c2b4c8
4 changed files with 87 additions and 72 deletions
@@ -21,6 +21,7 @@
NSString *_pwd;
}
@end
@@ -43,7 +44,6 @@
UInt16 bindPort = 9954;
NSError *error;
[self.clientSocket enableBroadcast:YES error:&error];
//本地接收端口
[self.clientSocket bindToPort:bindPort error:&error];
[self.clientSocket receiveWithTimeout:-1 tag:0];
@@ -60,10 +60,10 @@
- (void)broadCastRestCommand {
[self postmsg:@"命令已发出"];
[self sendRestSocketData];
[self sendResetSocketData];
}
- (void)sendRestSocketData {
- (void)sendResetSocketData {
NSString* hostS = @"192.168.4.1";
ResetDeviceModel *model = [ResetDeviceModel new];
NSString *request=[NSString stringWithFormat:@"%@", model.description];
@@ -72,12 +72,12 @@
UInt16 port = 333;
[self.clientSocket sendData:data toHost:hostS port:port withTimeout:-1 tag:1];
[self.clientSocket sendData:data toHost:hostS port:port withTimeout:-1 tag:0];
}
- (void)broadCastRestartCommand {
[self postmsg:@"命令已发出"];
[self sendRestSocketData];
[self sendRestartSocketData];
}
- (void)sendRestartSocketData {
@@ -90,7 +90,7 @@
UInt16 port = 333;
[self.clientSocket sendData:data toHost:hostS port:port withTimeout:-1 tag:1];
[self.clientSocket sendData:data toHost:hostS port:port withTimeout:-1 tag:0];
}
-(void)sendConnectHotspotSoketdata{
@@ -105,14 +105,11 @@
NSData *data=[dataContorl stringToHexData:request];
UInt16 port = 333;
[self.clientSocket sendData:data toHost:hostS port:port withTimeout:-1 tag:1];
[self.clientSocket sendData:data toHost:hostS port:port withTimeout:-1 tag:0];
}
-(BOOL)onUdpSocket:(AsyncUdpSocket *)sock didReceiveData:(NSData *)data withTag:(long)tag fromHost:(NSString *)host port:(UInt16)port
{
[self.loopTimer invalidate];
NSString* result = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
IFishUDPHelperBackMsgModel *model = [[IFishUDPHelperBackMsgModel alloc] initWithData:data];
if ([model.result isEqualToString:@"01"]) {
@@ -128,9 +125,7 @@
}
-(void)onUdpSocketDidClose:(AsyncUdpSocket *)sock{
[self.loopTimer invalidate];
NSLog(@"关闭");
NSLog(@"关闭");
}
@@ -144,16 +139,12 @@
NSLog(@"dueToError%@",error);
[self postmsg:error.localizedDescription];
[self.loopTimer invalidate];
}
-(void)dealloc{
[self.clientSocket close];
[self.loopTimer invalidate];
}
- (void)postmsg:(NSString *)msg {