// // FirstViewController.m // Talk // // Created by xuzs on 22/10/11. // Copyright (c) 2022年 xuzs. All rights reserved. // #import "P2pTest.h" #import "UI.h" #import "HttpManager.h" #import "Msg.h" #import "Pub.h" #import "sysInfo.h" #import "EquList.h" #import "HttpManager.h" #import "Sformat.h" #import @interface P2pTest () @property (nonatomic, strong)UIView *rview; @property (nonatomic, strong)NSArray *cells; @property (nonatomic, strong)UILabel *hitLabel; @property (nonatomic, strong)AppDelegate *app; @property (nonatomic, strong)NSString *remote_ipv6; @property (nonatomic)int remote_portv6; @property (nonatomic)int get_Address_type; @property (nonatomic)int get_Address_num; @property (nonatomic, strong)NSString *got_address; @property (nonatomic, strong)NSString *got_port; @end @implementation P2pTest - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent; self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:55/255. green:143/255. blue:232/255. alpha:1];//#378fe8 self.navigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent; [self setNavTitle:@"调试"]; [self setupViews]; [self setUI]; self.app = [Pub getApp]; } - (void)setupViews { [self.view addSubview:self.rview]; [self.rview addSubview:self. hitLabel]; for(int i=0;i-1){ [_app.talk SetRemoteIp:[_app.talk getIpFromBtye:bb At:57]]; [_app.talk SetRemotePort:[_app.talk getPortFromBtye:bb At:73] ]; self.hitLabel.text = [[NSString alloc] initWithFormat:@"%@\n解析成功:%@:%d" ,self.hitLabel.text,[_app.talk getRemoteIp],[_app.talk getRemotePort]]; [self Dadong1_wait]; } } } else{ if(bb[7]==1){// Byte bb0[1]; bb0[0]=0x30; NSData *data0 = [[NSData alloc] initWithBytes:bb length:1]; bb[7]=2; NSData *data = [[NSData alloc] initWithBytes:bb length:bblen]; [_app.udp.udp sendData:data0 toHost:@"2408:4003:10d1:8364:437c:392:f6c9:4ae7" port:8368 withTimeout:-1 tag:0]; [_app.udp.udp sendData:data toHost:@"2408:4003:10d1:8364:437c:392:f6c9:4ae7" port:8368 withTimeout:-1 tag:0]; _remote_ipv6 = [_app.talk getIpv6FromBtye:bb At:57]; _remote_portv6 = [_app.talk getPortFromBtye:bb At:73]; self.hitLabel.text = [[NSString alloc] initWithFormat:@"收到解析:%@:%d",_remote_ipv6,_remote_portv6]; // [_app.udp.udp sendData:data0 // toHost:_remote_ipv6 // port:_remote_portv6 // withTimeout:-1 // tag:0]; // [_app.udp.udp sendData:data0 // toHost:_remote_ipv6 // port:_remote_portv6 // withTimeout:-1 // tag:0]; [[Pub getApp].udp senddataInThr:data0 toHost:_remote_ipv6 toPort:_remote_portv6 at:4 setTag:0]; } else{ if([_app.udp stopSend:@"" rr6:bb[6] rr8:bb[8]]>-1){ _remote_ipv6 = [_app.talk getIpv6FromBtye:bb At:57]; _remote_portv6 = [_app.talk getPortFromBtye:bb At:73]; self.hitLabel.text = [[NSString alloc] initWithFormat:@"%@\n解析成功:%@:%d" ,self.hitLabel.text,_remote_ipv6,_remote_portv6]; Byte bb[512]; [_app.talk addHead:@"XXXCID" toByte:bb]; bb[6]=150; bb[7]=1; bb[8]=142; [_app.talk addEquid:[Pub getApp].sysinfo.equid addIp:[Pub getLocalIP] toByte:bb at:9]; [_app.talk addEquid:[_app.talk getRemoteEqu] addIp:[_app.talk getRemoteIp] toByte:bb at:33]; NSData *data = [[NSData alloc] initWithBytes:bb length:512]; [[Pub getApp].udp senddataInThr:data toHost:_remote_ipv6 toPort:_remote_portv6 at:3 setTag:0]; } } } } -(void)Talk1{ self.hitLabel.text = [[NSString alloc] initWithFormat:@"呼叫%@:%d",[_app.talk getRemoteIp],[_app.talk getRemotePort]]; Byte bb[512]; [_app.talk addHead:@"XXXCID" toByte:bb]; bb[6]=150; bb[7]=1; bb[8]=142; [_app.talk addEquid:[Pub getApp].sysinfo.equid addIp:[Pub getLocalIP] toByte:bb at:9]; [_app.talk addEquid:[_app.talk getRemoteEqu] addIp:[_app.talk getRemoteIp] toByte:bb at:33]; NSData *data = [[NSData alloc] initWithBytes:bb length:512]; //[app senddataInThr:data toHost:remoteIp byPort:8302]; [[Pub getApp].udp senddataInThr:data toHost:[_app.talk getRemoteIp] toPort:[_app.talk getRemotePort] at:3 setTag:0]; //[Pub getApp].udp senddataInThr:data toHost:self.remote_ipv6 toPort:self.remote_portv6 at:3 setTag:0]; } - (void)GotCall:(Byte *)bb Len:(int)bblen Formip:(NSString *)ip fromport:(int)port { if(bb[7]==1){ [_app.udp stopSendDadong]; self.hitLabel.text = [[NSString alloc] initWithFormat:@"%@\n被叫%@:%d",self.hitLabel.text,ip,port ]; bb[7]=2; NSData *data = [[NSData alloc] initWithBytes:bb length:bblen]; [_app.udp.udp sendData:data toHost:ip port:port withTimeout:-1 tag:0]; } else{ self.hitLabel.text = [[NSString alloc] initWithFormat:@"%@\n呼通%@:%d",self.hitLabel.text,ip,port ]; [_app.udp stopSend:ip rr6:bb[6] rr8:bb[8]]; } } - (void)GotDadong:(Byte *)bb Len:(int)bblen Formip:(NSString *)ip fromport:(int)port { if([ip componentsSeparatedByString:@"."].count==4){ self.hitLabel.text = [[NSString alloc] initWithFormat:@"%@\n被打洞(%d)%@:%d",self.hitLabel.text,bb[0],ip,port ]; [_app.talk SetRemoteIp:ip]; [_app.talk SetRemotePort:port ]; if(bb[0]==0x30){ bb[0] = 0x31; NSData *data = [[NSData alloc] initWithBytes:bb length:bblen]; [_app.udp.udp sendData:data toHost:ip port:port withTimeout:-1 tag:0]; } else{ [self Talk1]; } } else{ self.hitLabel.text = [[NSString alloc] initWithFormat:@"%@\n被打洞%@:%d",self.hitLabel.text,ip,port ]; _remote_ipv6 = ip; _remote_portv6 = port; [_app.udp ChgSendIp:ip rr6:150 rr8:142 Port:port]; } } - (void)Dadong1_wait{ [NSThread detachNewThreadSelector:@selector(Dadong1_thr) toTarget:self withObject:nil]; } -(void)Dadong1_thr{ sleep(2); dispatch_async(dispatch_get_main_queue(), ^{//转到主线程处理 [self Dadong1]; }); } -(void)Dadong1{ self.hitLabel.text = [[NSString alloc] initWithFormat:@"打洞%@:%d~%d",[_app.talk getRemoteIp],MAX(1000,[_app.talk getRemotePort]),MIN(65535,[_app.talk getRemotePort]+500)]; Byte bb[1]; bb[0]=0x30; NSData *data = [[NSData alloc] initWithBytes:bb length:1]; //[[Pub getApp].udp senddataInThr:data toHost:[_app.talk getRemoteIp] toPort:[_app.talk getRemotePort]+1 at:3 setTag:0]; // [_app.udp.udp sendData:data // toHost:self.remote_ipv6 // // port:800 // withTimeout:-1 // tag:0]; for(int i= MAX(1000,[_app.talk getRemotePort]);i" Color:[UIColor grayColor] Size:15. Align:(NSTextAlignmentRight)]]; UIView *cell2 = [[UIView alloc] init]; cell2.backgroundColor = [UIColor whiteColor]; [cell2 addSubview:[UI NewLabel:@"对方环境" Color:[UIColor blackColor] Size:15. Align:(NSTextAlignmentLeft)]]; [cell2 addSubview:[UI NewLabel:@">" Color:[UIColor grayColor] Size:15. Align:(NSTextAlignmentRight)]]; UIView *cell3 = [[UIView alloc] init]; cell3.backgroundColor = [UIColor whiteColor]; [cell3 addSubview:[UI NewLabel:@"呼叫模式1" Color:[UIColor blackColor] Size:15. Align:(NSTextAlignmentLeft)]]; [cell3 addSubview:[UI NewLabel:@">" Color:[UIColor grayColor] Size:15. Align:(NSTextAlignmentRight)]]; UIView *cell4 = [[UIView alloc] init]; cell4.backgroundColor = [UIColor whiteColor]; [cell4 addSubview:[UI NewLabel:@"打洞模式1" Color:[UIColor blackColor] Size:15. Align:(NSTextAlignmentLeft)]]; [cell4 addSubview:[UI NewLabel:@">" Color:[UIColor grayColor] Size:15. Align:(NSTextAlignmentRight)]]; UIView *cell5 = [[UIView alloc] init]; cell5.backgroundColor = [UIColor whiteColor]; [cell5 addSubview:[UI NewLabel:@"网络环境2" Color:[UIColor blackColor] Size:15. Align:(NSTextAlignmentLeft)]]; [cell5 addSubview:[UI NewLabel:@">" Color:[UIColor grayColor] Size:15. Align:(NSTextAlignmentRight)]]; UIView *cell6 = [[UIView alloc] init]; cell6.backgroundColor = [UIColor whiteColor]; [cell6 addSubview:[UI NewLabel:@"ipv4一键呼叫" Color:[UIColor blackColor] Size:15. Align:(NSTextAlignmentLeft)]]; [cell6 addSubview:[UI NewLabel:@">" Color:[UIColor grayColor] Size:15. Align:(NSTextAlignmentRight)]]; UIView *cell7 = [[UIView alloc] init]; cell7.backgroundColor = [UIColor whiteColor]; [cell7 addSubview:[UI NewLabel:@"ipv6一键呼叫" Color:[UIColor blackColor] Size:15. Align:(NSTextAlignmentLeft)]]; [cell7 addSubview:[UI NewLabel:@">" Color:[UIColor grayColor] Size:15. Align:(NSTextAlignmentRight)]]; _cells = @[cell1,cell2,cell3,cell4,cell5,cell6,cell7]; } return _cells; } - (UILabel *) hitLabel { if (!_hitLabel) { _hitLabel = [[UILabel alloc] init]; //_webView.backgroundColor = [UIColor colorWithRed:241/255. green:241/255. blue:241/255. alpha:1]; _hitLabel.font = [UIFont systemFontOfSize:13.0f]; _hitLabel.textColor = [UIColor blackColor]; _hitLabel.textAlignment = NSTextAlignmentLeft; _hitLabel.text = NSLocalizedString(@"", nil); _hitLabel.numberOfLines = 0; } return _hitLabel; } @end