|
@@ -22,6 +22,7 @@ |
|
@@ -22,6 +22,7 @@ |
22
|
{
|
22
|
{
|
23
|
BOOL _hasLoginWithNameSuccessed;
|
23
|
BOOL _hasLoginWithNameSuccessed;
|
24
|
BOOL _hasLoginWithDevieToken;
|
24
|
BOOL _hasLoginWithDevieToken;
|
|
|
25
|
+ BOOL _needSendStartPackage;
|
25
|
}
|
26
|
}
|
26
|
@property (strong, nonatomic) NSTimer *connectTimer;
|
27
|
@property (strong, nonatomic) NSTimer *connectTimer;
|
27
|
@property (strong, nonatomic) NSTimer *heartBeatTimer;
|
28
|
@property (strong, nonatomic) NSTimer *heartBeatTimer;
|
|
@@ -37,6 +38,7 @@ |
|
@@ -37,6 +38,7 @@ |
37
|
{
|
38
|
{
|
38
|
self = [super init];
|
39
|
self = [super init];
|
39
|
if (self) {
|
40
|
if (self) {
|
|
|
41
|
+ _needSendStartPackage = YES;
|
40
|
self.socket = [[GCDAsyncSocket alloc]initWithDelegate:self delegateQueue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)];
|
42
|
self.socket = [[GCDAsyncSocket alloc]initWithDelegate:self delegateQueue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)];
|
41
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(networkReachabilityDidChange:) name:AFNetworkingReachabilityDidChangeNotification object:nil];
|
43
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(networkReachabilityDidChange:) name:AFNetworkingReachabilityDidChangeNotification object:nil];
|
42
|
self.deviceToken = [NSString stringWithFormat:@"%f",[[NSDate date] timeIntervalSince1970]];
|
44
|
self.deviceToken = [NSString stringWithFormat:@"%f",[[NSDate date] timeIntervalSince1970]];
|
|
@@ -197,12 +199,14 @@ |
|
@@ -197,12 +199,14 @@ |
197
|
- (void)socket:(GCDAsyncSocket *)sock didConnectToHost:(NSString *)host port:(uint16_t)port
|
199
|
- (void)socket:(GCDAsyncSocket *)sock didConnectToHost:(NSString *)host port:(uint16_t)port
|
198
|
{
|
200
|
{
|
199
|
DLog(@"socket connect success!");
|
201
|
DLog(@"socket connect success!");
|
200
|
- NSDictionary *params = @{@"cmd":@(14),
|
|
|
201
|
- @"room":self.room?:@"666",
|
|
|
202
|
- @"msg":@"",
|
|
|
203
|
- @"uid":@""
|
|
|
204
|
- };
|
|
|
205
|
- [_socket writeDataWithParams:params tag:14];
|
202
|
+ if (_needSendStartPackage) {
|
|
|
203
|
+ NSDictionary *params = @{@"cmd":@(SOCKET_TAG_Start),
|
|
|
204
|
+ @"room":self.room?:@"666",
|
|
|
205
|
+ @"msg":@"",
|
|
|
206
|
+ @"uid":@""
|
|
|
207
|
+ };
|
|
|
208
|
+ [_socket writeDataWithParams:params tag:SOCKET_TAG_Start];
|
|
|
209
|
+ }
|
206
|
self.heartBeatTimer = [NSTimer scheduledTimerWithTimeInterval:TimeIntervalForHeartBeat target:self selector:@selector(_heartbeat) userInfo:nil repeats:YES];
|
210
|
self.heartBeatTimer = [NSTimer scheduledTimerWithTimeInterval:TimeIntervalForHeartBeat target:self selector:@selector(_heartbeat) userInfo:nil repeats:YES];
|
207
|
[self listenData];
|
211
|
[self listenData];
|
208
|
}
|
212
|
}
|
|
@@ -237,9 +241,10 @@ |
|
@@ -237,9 +241,10 @@ |
237
|
}
|
241
|
}
|
238
|
break;
|
242
|
break;
|
239
|
|
243
|
|
240
|
- case 14:
|
244
|
+ case SOCKET_TAG_Start:
|
241
|
{
|
245
|
{
|
242
|
[self loginToServer];
|
246
|
[self loginToServer];
|
|
|
247
|
+ _needSendStartPackage = NO;
|
243
|
}
|
248
|
}
|
244
|
break;
|
249
|
break;
|
245
|
default:
|
250
|
default:
|
|
@@ -350,6 +355,7 @@ |
|
@@ -350,6 +355,7 @@ |
350
|
[self.connectTimer invalidate];
|
355
|
[self.connectTimer invalidate];
|
351
|
self.connectTimer = nil;
|
356
|
self.connectTimer = nil;
|
352
|
}
|
357
|
}
|
|
|
358
|
+ _needSendStartPackage = YES;
|
353
|
[_socket disconnect];
|
359
|
[_socket disconnect];
|
354
|
}
|
360
|
}
|
355
|
|
361
|
|