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