端口释放的优化
This commit is contained in:
parent
801450b271
commit
78c0096abb
|
|
@ -51,16 +51,16 @@
|
|||
_tag = 0;
|
||||
_returnRandomNum = 0;
|
||||
_connectionDone = false;
|
||||
self._parameter = [[ESPTaskParameter alloc]init];
|
||||
|
||||
// check whether IPv4 and IPv6 is supported
|
||||
NSString *localInetAddr4 = [ESP_NetUtil getLocalIPv4];
|
||||
if (![ESP_NetUtil isIPv4PrivateAddr:localInetAddr4]) {
|
||||
localInetAddr4 = nil;
|
||||
}
|
||||
NSString *localInetAddr6 = [ESP_NetUtil getLocalIPv6];
|
||||
[self._parameter setIsIPv4Supported:localInetAddr4!=nil];
|
||||
[self._parameter setIsIPv6Supported:localInetAddr6!=nil];
|
||||
// self._parameter = [[ESPTaskParameter alloc]init];
|
||||
//
|
||||
// // check whether IPv4 and IPv6 is supported
|
||||
// NSString *localInetAddr4 = [ESP_NetUtil getLocalIPv4];
|
||||
// if (![ESP_NetUtil isIPv4PrivateAddr:localInetAddr4]) {
|
||||
// localInetAddr4 = nil;
|
||||
// }
|
||||
// NSString *localInetAddr6 = [ESP_NetUtil getLocalIPv6];
|
||||
// [self._parameter setIsIPv4Supported:localInetAddr4!=nil];
|
||||
// [self._parameter setIsIPv6Supported:localInetAddr6!=nil];
|
||||
|
||||
[self setupClientUdpSocket];
|
||||
[self setupServerUdpSocket];
|
||||
|
|
@ -143,11 +143,19 @@
|
|||
{
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
NSLog(@"airkiss socket error= %@",error.description);
|
||||
}
|
||||
|
||||
if (![_clientUdpSocket beginReceiving:&error])
|
||||
{
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
NSLog(@"airkiss socket error= %@",error.description);
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setupServerUdpSocket {
|
||||
|
|
@ -162,11 +170,19 @@
|
|||
{
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
NSLog(@"airkiss socket error= %@",error.description);
|
||||
}
|
||||
|
||||
if (![_serverUdpSocket beginReceiving:&error])
|
||||
{
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
NSLog(@"airkiss socket error= %@",error.description);
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - Event Response
|
||||
|
|
@ -178,6 +194,7 @@
|
|||
|
||||
if (_connectionFailure) {
|
||||
_connectionFailure();
|
||||
[self closeConnection];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -202,11 +219,18 @@ withFilterContext:(id)filterContext
|
|||
return;
|
||||
}
|
||||
NSString* serIp = [GCDAsyncUdpSocket hostFromAddress:address];
|
||||
NSLog(@"serIp=%@",serIp);
|
||||
serIp= [serIp stringByReplacingOccurrencesOfString:@"::ffff:" withString:@""];
|
||||
uint16_t serPort = (int)[GCDAsyncUdpSocket portFromAddress:address];
|
||||
|
||||
|
||||
//uint16_t serPort = (int)[GCDAsyncUdpSocket portFromAddress:address];
|
||||
if ([serIp isEqualToString:_localIP]) {
|
||||
return;//是本机的数据直接返回
|
||||
}
|
||||
else
|
||||
{
|
||||
NSLog(@"收到回包=%@",data);
|
||||
}
|
||||
// 设备连接WIFI成功后会像10000端口发送至少20个UDP广播包所附带的随机数
|
||||
if (data != nil) {
|
||||
UInt8 *bytes = (UInt8 *) [data bytes];
|
||||
|
|
@ -224,6 +248,7 @@ withFilterContext:(id)filterContext
|
|||
NSString*macstring = [self.class dataToHexString:MacData];
|
||||
if (_connectionSuccess) {
|
||||
_connectionSuccess(macstring);
|
||||
[self closeConnection];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -321,4 +346,8 @@ withFilterContext:(id)filterContext
|
|||
return data;
|
||||
|
||||
}
|
||||
-(void)dealloc
|
||||
{
|
||||
NSLog(@"cnn dealloc");
|
||||
}
|
||||
@end
|
||||
|
|
|
|||
|
|
@ -201,6 +201,11 @@ extern BOOL isfromCameraView;
|
|||
-(void)goBackAction{
|
||||
if(self.connectingView.hidden==NO)
|
||||
{
|
||||
if(_airKissConnection)
|
||||
{
|
||||
[_airKissConnection closeConnection];
|
||||
_airKissConnection = nil;
|
||||
}
|
||||
[self connectNormalView];
|
||||
}
|
||||
else
|
||||
|
|
@ -620,11 +625,16 @@ extern BOOL isfromCameraView;
|
|||
- (void)configWifiForDevice{
|
||||
|
||||
NSLog(@"ViewController do confirm action...");
|
||||
|
||||
if(_airKissConnection)
|
||||
{
|
||||
[_airKissConnection closeConnection];
|
||||
_airKissConnection = nil;
|
||||
}
|
||||
WEAK_SELF;
|
||||
void(^success)(NSString*deviceBssid)=^(NSString*deviceBssid)
|
||||
{
|
||||
|
||||
_deviceBssid=deviceBssid;
|
||||
weakSelf.airKissConnection=nil;
|
||||
weakSelf.deviceBssid=deviceBssid;
|
||||
|
||||
NSArray*arry=[[DataCenter defaultDtacenter]valueForKey:@"deviceInfo"];
|
||||
DeviceModel*model=[[DeviceModel alloc]init];
|
||||
|
|
@ -639,21 +649,21 @@ extern BOOL isfromCameraView;
|
|||
BOOL exst=[macdressArr containsObject:_deviceBssid];
|
||||
if (exst) {
|
||||
|
||||
self.lodviewMissStyle=lodingViewdissMissAlreadyBinded;
|
||||
[self mmPogressHUDdismiss];
|
||||
[self connectNormalView];
|
||||
self.bakbutton.userInteractionEnabled=YES;
|
||||
weakSelf.lodviewMissStyle=lodingViewdissMissAlreadyBinded;
|
||||
[weakSelf mmPogressHUDdismiss];
|
||||
[weakSelf connectNormalView];
|
||||
weakSelf.bakbutton.userInteractionEnabled=YES;
|
||||
//[self.navigationController popViewControllerAnimated:YES];
|
||||
[self.view makeToast:@"该设备已存在"];
|
||||
[weakSelf.view makeToast:@"该设备已存在"];
|
||||
|
||||
}else{
|
||||
|
||||
if (self.deviceType==DEVICEPETS) {
|
||||
[self showStoreNameView];
|
||||
if (weakSelf.deviceType==DEVICEPETS) {
|
||||
[weakSelf showStoreNameView];
|
||||
}
|
||||
else
|
||||
{
|
||||
[self bindDeviceWithSsid:_deviceBssid];
|
||||
[weakSelf bindDeviceWithSsid:_deviceBssid];
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -666,17 +676,18 @@ extern BOOL isfromCameraView;
|
|||
|
||||
void(^failure)(NSError*error,NSString*msg)=^(NSError*error,NSString*msg)
|
||||
{
|
||||
self.lodviewMissStyle=lodingViewdissMissfail;
|
||||
[self mmPogressHUDdismiss];
|
||||
[self connectNormalView];
|
||||
self.bakbutton.userInteractionEnabled=YES;
|
||||
weakSelf.airKissConnection=nil;
|
||||
weakSelf.lodviewMissStyle=lodingViewdissMissfail;
|
||||
[weakSelf mmPogressHUDdismiss];
|
||||
[weakSelf connectNormalView];
|
||||
weakSelf.bakbutton.userInteractionEnabled=YES;
|
||||
if(msg.length)
|
||||
{
|
||||
[self.view makeToast:msg];
|
||||
[weakSelf.view makeToast:msg];
|
||||
}
|
||||
[self showFailResultViewWithMsg:msg];
|
||||
[weakSelf showFailResultViewWithMsg:msg];
|
||||
};
|
||||
ConnectType type = self.connectType;
|
||||
ConnectType type = weakSelf.connectType;
|
||||
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
|
||||
if(type == ConnectTypeAirKiss)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue