Skip to content
This repository was archived by the owner on May 14, 2024. It is now read-only.

Commit 5ed977c

Browse files
committed
fixes connect/disconnect problems #46
1 parent 91db6ca commit 5ed977c

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

SocketIO.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ typedef enum {
7575
BOOL _isConnecting;
7676
BOOL _useSecure;
7777

78+
NSURLConnection *_handshake;
79+
7880
// heartbeat
7981
NSTimeInterval _heartbeatTimeout;
8082
NSTimer *_timeout;

SocketIO.m

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,21 +138,26 @@ - (void) connectToHost:(NSString *)host onPort:(NSInteger)port withParams:(NSDic
138138
cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData
139139
timeoutInterval:10.0];
140140

141-
NSURLConnection *connection = [NSURLConnection connectionWithRequest:request
142-
delegate:self];
143-
if (connection) {
141+
_handshake = [NSURLConnection connectionWithRequest:request
142+
delegate:self];
143+
if (_handshake) {
144144
_httpRequestData = [NSMutableData data];
145145
}
146146
else {
147147
// connection failed
148-
[self connection:connection didFailWithError:nil];
148+
[self connection:_handshake didFailWithError:nil];
149149
}
150150
}
151151
}
152152

153153
- (void) disconnect
154154
{
155-
[self sendDisconnect];
155+
if (_isConnected) {
156+
[self sendDisconnect];
157+
}
158+
else if (_isConnecting) {
159+
[_handshake cancel];
160+
}
156161
}
157162

158163
- (void) sendMessage:(NSString *)data

0 commit comments

Comments
 (0)