...
|
...
|
@@ -22,6 +22,7 @@ |
|
|
{
|
|
|
BOOL _hasLoginWithNameSuccessed;
|
|
|
BOOL _hasLoginWithDevieToken;
|
|
|
BOOL _needSendStartPackage;
|
|
|
}
|
|
|
@property (strong, nonatomic) NSTimer *connectTimer;
|
|
|
@property (strong, nonatomic) NSTimer *heartBeatTimer;
|
...
|
...
|
@@ -37,6 +38,7 @@ |
|
|
{
|
|
|
self = [super init];
|
|
|
if (self) {
|
|
|
_needSendStartPackage = YES;
|
|
|
self.socket = [[GCDAsyncSocket alloc]initWithDelegate:self delegateQueue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)];
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(networkReachabilityDidChange:) name:AFNetworkingReachabilityDidChangeNotification object:nil];
|
|
|
self.deviceToken = [NSString stringWithFormat:@"%f",[[NSDate date] timeIntervalSince1970]];
|
...
|
...
|
@@ -197,12 +199,14 @@ |
|
|
- (void)socket:(GCDAsyncSocket *)sock didConnectToHost:(NSString *)host port:(uint16_t)port
|
|
|
{
|
|
|
DLog(@"socket connect success!");
|
|
|
NSDictionary *params = @{@"cmd":@(14),
|
|
|
@"room":self.room?:@"666",
|
|
|
@"msg":@"",
|
|
|
@"uid":@""
|
|
|
};
|
|
|
[_socket writeDataWithParams:params tag:14];
|
|
|
if (_needSendStartPackage) {
|
|
|
NSDictionary *params = @{@"cmd":@(SOCKET_TAG_Start),
|
|
|
@"room":self.room?:@"666",
|
|
|
@"msg":@"",
|
|
|
@"uid":@""
|
|
|
};
|
|
|
[_socket writeDataWithParams:params tag:SOCKET_TAG_Start];
|
|
|
}
|
|
|
self.heartBeatTimer = [NSTimer scheduledTimerWithTimeInterval:TimeIntervalForHeartBeat target:self selector:@selector(_heartbeat) userInfo:nil repeats:YES];
|
|
|
[self listenData];
|
|
|
}
|
...
|
...
|
@@ -237,9 +241,10 @@ |
|
|
}
|
|
|
break;
|
|
|
|
|
|
case 14:
|
|
|
case SOCKET_TAG_Start:
|
|
|
{
|
|
|
[self loginToServer];
|
|
|
_needSendStartPackage = NO;
|
|
|
}
|
|
|
break;
|
|
|
default:
|
...
|
...
|
@@ -350,6 +355,7 @@ |
|
|
[self.connectTimer invalidate];
|
|
|
self.connectTimer = nil;
|
|
|
}
|
|
|
_needSendStartPackage = YES;
|
|
|
[_socket disconnect];
|
|
|
}
|
|
|
|
...
|
...
|
|