584 lines
24 KiB
Objective-C
Executable File
584 lines
24 KiB
Objective-C
Executable File
//
|
||
// 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 <math.h>
|
||
|
||
@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<self.cells.count;i++){
|
||
[self.rview addSubview:self.cells[i]];
|
||
|
||
if(i==0){
|
||
[self.cells[i] addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(GetMyPortInServer)]];
|
||
}
|
||
else if(i==1){
|
||
[self.cells[i] addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(GetRemoteIp)]];
|
||
}
|
||
else if(i==2){
|
||
[self.cells[i] addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(Talk1)]];
|
||
}
|
||
else if(i==3){
|
||
[self.cells[i] addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(Dadong1)]];
|
||
}
|
||
else if(i==4){
|
||
[self.cells[i] addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(GetMyPortInServer2)]];
|
||
}
|
||
else if(i==5){
|
||
[self.cells[i] addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(Call_ipv4)]];
|
||
}
|
||
else if(i==6){
|
||
[self.cells[i] addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(Call)]];
|
||
}
|
||
|
||
}
|
||
|
||
}
|
||
- (void)GetMyPortInServer{
|
||
self.hitLabel.text = @"本地网络:";
|
||
self.get_Address_type = 1;
|
||
self.get_Address_num = 5;
|
||
self.got_port = @"";
|
||
self.got_address = @"";
|
||
|
||
Byte bb[512];
|
||
[_app.talk addHead:@"XXXCID" toByte:bb];
|
||
bb[6]=150;
|
||
bb[7]=1;
|
||
bb[8]=140;
|
||
[_app.talk addEquid:_app.sysinfo.equid addIp:[Pub getLocalIP] toByte:bb at:9];
|
||
//[self addEquid:[Pub getApp].sysinfo.equid addIp:[Pub getLocalIP] toByte:bb at:33];
|
||
|
||
|
||
NSData *data = [[NSData alloc] initWithBytes:bb length:512];
|
||
[_app.udp senddataInThr:data toHost:_app.sysinfo.server_wan toPort:8366 at:3 setTag:0];
|
||
[_app.udp senddataInThr:data toHost:_app.sysinfo.server_wan toPort:8367 at:3 setTag:0];
|
||
//[_app.udp senddataInThr:data toHost:@"47.107.109.110" toPort:8366 at:3 setTag:0];
|
||
[_app.udp senddataInThr:data toHost:@"47.107.109.110" toPort:8367 at:3 setTag:0];
|
||
[_app.udp senddataInThr:data toHost:@"2408:4003:10d1:8364:437c:392:f6c9:4ae7" toPort:8368 at:3 setTag:0];
|
||
[_app.udp senddataInThr:data toHost:@"180.76.97.209" toPort:8366 at:3 setTag:0];
|
||
}
|
||
- (void)GetMyPortInServer2{
|
||
self.hitLabel.text = @"本地网络:";
|
||
self.get_Address_type = 2;
|
||
|
||
Byte bb[512];
|
||
[_app.talk addHead:@"XXXCID" toByte:bb];
|
||
bb[6]=150;
|
||
bb[7]=1;
|
||
bb[8]=140;
|
||
[_app.talk addEquid:_app.sysinfo.equid addIp:[Pub getLocalIP] toByte:bb at:9];
|
||
//[self addEquid:[Pub getApp].sysinfo.equid addIp:[Pub getLocalIP] toByte:bb at:33];
|
||
|
||
|
||
NSData *data = [[NSData alloc] initWithBytes:bb length:512];
|
||
//[_app.udp senddataInThr:data toHost:_app.sysinfo.server_wan toPort:8369 at:3 setTag:0];
|
||
[_app.udp senddataInThr:data toHost:@"180.76.97.209" toPort:8367 at:3 setTag:0];
|
||
}
|
||
- (void)GotMyPortInServer:(Byte *)bb Len:(int)bblen Formip:(NSString *)ip fromport:(int)port {
|
||
[_app.udp stopSend:ip rr6:bb[6] rr8:bb[8] Port:port];
|
||
NSString *got_address1 = [[NSString alloc] initWithFormat:@"%@:%d;",ip,port ];
|
||
self.got_address = [[NSString alloc] initWithFormat:@"%@%@",[self.got_address stringByReplacingOccurrencesOfString:got_address1 withString:@""],got_address1 ];
|
||
if([[_app.talk getIpFromBtye:bb At:29] isEqual:@"255.255.255.255"]){
|
||
self.hitLabel.text = [[NSString alloc] initWithFormat:@"%@\n%@:%d",self.hitLabel.text,[_app.talk getIpv6FromBtye:bb At:35],[_app.talk getPortFromBtye:bb At:33] ];
|
||
}
|
||
else{
|
||
self.hitLabel.text = [[NSString alloc] initWithFormat:@"%@\n%@:%d反馈%@:%d",self.hitLabel.text,ip,port,[_app.talk getIpFromBtye:bb At:29],[_app.talk getPortFromBtye:bb At:33]];
|
||
NSString *got_port1 = [[NSString alloc] initWithFormat:@"%d;",[_app.talk getPortFromBtye:bb At:33] ];
|
||
self.got_port = [[NSString alloc] initWithFormat:@"%@%@",[self.got_port stringByReplacingOccurrencesOfString:got_port1 withString:@""],got_port1 ];
|
||
}
|
||
|
||
if(self.get_Address_type==1){
|
||
NSString *ipv6 = @"ipv6不可用";
|
||
if([self.got_address rangeOfString:@"8369;"].location!=NSNotFound){
|
||
if([self.got_address componentsSeparatedByString:@";"].count==self.get_Address_num+2){
|
||
if([self.got_address rangeOfString:@"2408:4003:10d1:8364:437c"].location!=NSNotFound){
|
||
ipv6 = @"ipv6可用";
|
||
}
|
||
self.hitLabel.text = [[NSString alloc] initWithFormat:@"%@\nip限制型,%@",self.hitLabel.text,ipv6 ];
|
||
}
|
||
}
|
||
else{
|
||
if([self.got_address componentsSeparatedByString:@";"].count==self.get_Address_num+1){
|
||
if([self.got_address rangeOfString:@"2408:4003:10d1:8364:437c"].location!=NSNotFound){
|
||
ipv6 = @"ipv6可用";
|
||
}
|
||
if([self.got_port componentsSeparatedByString:@";"].count== 2){
|
||
self.hitLabel.text = [[NSString alloc] initWithFormat:@"%@\n端口限制型,%@",self.hitLabel.text,ipv6 ];
|
||
}
|
||
else{
|
||
self.hitLabel.text = [[NSString alloc] initWithFormat:@"%@\n对称型,%@,端口变化:%d",self.hitLabel.text,ipv6,[self portRang:self.got_port] ];
|
||
}
|
||
}
|
||
else if([self.got_address componentsSeparatedByString:@";"].count==self.get_Address_num){
|
||
if([self.got_address rangeOfString:@"2408:4003:10d1:8364:437c"].location==NSNotFound){
|
||
if([self.got_port componentsSeparatedByString:@";"].count== 2){
|
||
self.hitLabel.text = [[NSString alloc] initWithFormat:@"%@\n端口限制型,%@",self.hitLabel.text,ipv6 ];
|
||
}
|
||
else{
|
||
self.hitLabel.text = [[NSString alloc] initWithFormat:@"%@\n对称型,%@,端口变化:%d",self.hitLabel.text,ipv6,[self portRang:self.got_port] ];
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
else if (self.get_Address_type==2){
|
||
self.hitLabel.text = [[NSString alloc] initWithFormat:@"%@\n端口变化:%d",self.hitLabel.text,[self portRang:self.got_port] ];
|
||
}
|
||
|
||
|
||
}
|
||
- (int)portRang:(NSString *)str{
|
||
|
||
NSArray *ports = [str componentsSeparatedByString:@";"];
|
||
int max = 0;
|
||
int min = 0;
|
||
for(int i=0;i<ports.count-1;i++){
|
||
int add = [[ports objectAtIndex:i] intValue]-[[ports objectAtIndex:0] intValue];
|
||
NSLog(@"add: %d",add);
|
||
max = MAX(max, add);
|
||
min = MIN(min, add);
|
||
}
|
||
|
||
return max-min;
|
||
}
|
||
- (void)GetRemoteIp{
|
||
if([_app.sysinfo.equid isEqual:@"P13430525341"]){
|
||
[_app.talk SetRemoteEqu:@"P13113619408"];
|
||
}else{
|
||
[_app.talk SetRemoteEqu:@"P13430525341"];
|
||
}
|
||
|
||
self.hitLabel.text = @"对方网络:";
|
||
Byte bb[512];
|
||
[_app.talk addHead:@"XXXCID" toByte:bb];
|
||
bb[6]=150;
|
||
bb[7]=1;
|
||
bb[8]=141;
|
||
[_app.talk addEquid:_app.sysinfo.equid addIp:[Pub getLocalIP] toByte:bb at:9];
|
||
[_app.talk addEquid:[_app.talk getRemoteEqu] addIp:[Pub getLocalIP] toByte:bb at:33];
|
||
|
||
|
||
NSData *data = [[NSData alloc] initWithBytes:bb length:512];
|
||
[_app.udp senddataInThr:data toHost:_app.sysinfo.server_wan toPort:8367 at:3 setTag:0];
|
||
//[_app.udp senddataInThr:data toHost:@"47.107.109.110" toPort:8367 at:3 setTag:0];
|
||
}
|
||
- (void)GotRemoteIp:(Byte *)bb Len:(int)bblen Formip:(NSString *)ip fromport:(int)port {
|
||
[_app.udp stopSend:ip rr6:bb[6] rr8:bb[8] Port:port];
|
||
[_app.talk SetRemoteIp:[_app.talk getIpFromBtye:bb At:29]];
|
||
[_app.talk SetRemotePort:[_app.talk getPortFromBtye:bb At:33] ];
|
||
_remote_ipv6 = [_app.talk getIpv6FromBtye:bb At:35];
|
||
_remote_portv6 = [_app.talk getPortFromBtye:bb At:51];
|
||
self.hitLabel.text = [[NSString alloc] initWithFormat:@"%@\n%@:%d\n%@:%d",self.hitLabel.text,[_app.talk getIpFromBtye:bb At:29],[_app.talk getPortFromBtye:bb At:33] ,_remote_ipv6,_remote_portv6];
|
||
}
|
||
- (void)Call_ipv4{
|
||
if([_app.sysinfo.equid isEqual:@"P13430525341"]){
|
||
[_app.talk SetRemoteEqu:@"P13113619408"];
|
||
}else{
|
||
[_app.talk SetRemoteEqu:@"P13430525341"];
|
||
}
|
||
|
||
|
||
|
||
self.hitLabel.text = [[NSString alloc] initWithFormat:@"呼叫%@",[_app.talk getRemoteEqu]];
|
||
Byte bb[512];
|
||
[_app.talk addHead:@"XXXCID" toByte:bb];
|
||
bb[6]=150;
|
||
bb[7]=1;
|
||
bb[8]=144;
|
||
[_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.sysinfo.server_wan toPort:8367 at:10 setTag:0];
|
||
}
|
||
- (void)Call{
|
||
if([_app.sysinfo.equid isEqual:@"P13430525341"]){
|
||
[_app.talk SetRemoteEqu:@"P13113619408"];
|
||
}else{
|
||
[_app.talk SetRemoteEqu:@"P13430525341"];
|
||
}
|
||
|
||
|
||
|
||
self.hitLabel.text = [[NSString alloc] initWithFormat:@"呼叫%@",[_app.talk getRemoteEqu]];
|
||
Byte bb[512];
|
||
[_app.talk addHead:@"XXXCID" toByte:bb];
|
||
bb[6]=150;
|
||
bb[7]=1;
|
||
bb[8]=143;
|
||
[_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:@"2408:4003:10d1:8364:437c:392:f6c9:4ae7" toPort:8368 at:10 setTag:0];
|
||
}
|
||
- (void)GotNSAsk:(Byte *)bb Len:(int)bblen Formip:(NSString *)ip fromport:(int)port {
|
||
if(bb[8]==144){
|
||
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:_app.sysinfo.server_wan
|
||
port:8367
|
||
withTimeout:-1
|
||
tag:0];
|
||
[_app.udp.udp sendData:data
|
||
toHost:_app.sysinfo.server_wan
|
||
port:8367
|
||
withTimeout:-1
|
||
tag:0];
|
||
|
||
[_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];
|
||
}
|
||
else{
|
||
|
||
if([_app.udp stopSend:@"" rr6:bb[6] rr8:bb[8]]>-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<MIN(65535,[_app.talk getRemotePort]+500);i++){
|
||
//dispatch_async(dispatch_get_main_queue(), ^{//转到主线程处理
|
||
[_app.udp.udp sendData:data
|
||
toHost:[_app.talk getRemoteIp]
|
||
port:i
|
||
withTimeout:-1
|
||
tag:0];
|
||
|
||
// [_app.udp.udp sendData:data
|
||
// toHost:[_app.talk getRemoteIp]
|
||
// port:i
|
||
// withTimeout:-1
|
||
// tag:0];
|
||
//});
|
||
|
||
}
|
||
|
||
}
|
||
-(void)Dadong2{
|
||
|
||
self.hitLabel.text = [[NSString alloc] initWithFormat:@"打洞%@:%d",[_app.talk getRemoteIp],[_app.talk getRemotePort]];
|
||
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:[_app.talk getRemoteIp]
|
||
port:[_app.talk getRemotePort]
|
||
withTimeout:-1
|
||
tag:0];
|
||
|
||
// self.hitLabel.text = [[NSString alloc] initWithFormat:@"打洞%@",[_app.talk getRemoteIp]];
|
||
// [NSThread detachNewThreadSelector:@selector(Dadong2_thr) toTarget:self withObject:nil];
|
||
}
|
||
|
||
- (void)setUI{
|
||
|
||
|
||
|
||
[UI SetRView:self.rview Top:@"0" Right:@"0" Bottom:@"0" Left:@"0"];
|
||
|
||
//self.scrollView.contentSize=CGSizeMake( [UI getScreenWidth],4000);
|
||
//self. hitLabel.frame = CGRectMake(0,0,[UI getScreenWidth], 4000);
|
||
|
||
[UI setFrameInView:self.hitLabel Width:@"100vw" Height:@"160" TranslateX:@"0" TranslateY:[[NSString alloc] initWithFormat:@"%f",[UI getStatuAndStatuHeight]] InView:nil Position:UITopMid];
|
||
|
||
for(int i=0;i<self.cells.count;i++){
|
||
NSString *top = [[NSString alloc] initWithFormat:@"%f", 10. + i*60.5] ;
|
||
[UI setFrameByView:self.cells[i] Width:@"100vw" Height:@"60" TranslateX:@"0" TranslateY:top ByView:self.hitLabel Position:BottomAlignCenter];
|
||
|
||
[UI setFrameInView:((UIView *)self.cells[i]).subviews[0] Width:@"70vw" Height:@"60" TranslateX:@"16" TranslateY:@"0" InView:nil Position:UIMidLeft];
|
||
[UI setFrameInView:((UIView *)self.cells[i]).subviews[1] Width:@"30vw" Height:@"60" TranslateX:@"16" TranslateY:@"0" InView:nil Position:UIMidRight];
|
||
|
||
|
||
}
|
||
}
|
||
|
||
- (void)didReceiveMemoryWarning {
|
||
[super didReceiveMemoryWarning];
|
||
// Dispose of any resources that can be recreated.
|
||
}
|
||
|
||
#pragma mark Property Accessors
|
||
- (UIView *)rview
|
||
{
|
||
if (!_rview) {
|
||
_rview = [[UIView alloc] init];
|
||
_rview.backgroundColor = [UIColor colorWithRed:241/255. green:241/255. blue:241/255. alpha:1];
|
||
}
|
||
return _rview;
|
||
}
|
||
|
||
|
||
- (NSArray *)cells{
|
||
if (!_cells) {
|
||
UIView *cell1 = [[UIView alloc] init];
|
||
cell1.backgroundColor = [UIColor whiteColor];
|
||
[cell1 addSubview:[UI NewLabel:@"网络环境" Color:[UIColor blackColor] Size:15. Align:(NSTextAlignmentLeft)]];
|
||
[cell1 addSubview:[UI NewLabel:@">" 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
|