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

Commit 29c6894

Browse files
committed
Add support for synchronous disconnect. close #112.
2 parents 3acdb80 + bc83082 commit 29c6894

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

SocketIO.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ typedef enum {
108108
- (void) connectToHost:(NSString *)host onPort:(NSInteger)port withParams:(NSDictionary *)params;
109109
- (void) connectToHost:(NSString *)host onPort:(NSInteger)port withParams:(NSDictionary *)params withNamespace:(NSString *)endpoint;
110110
- (void) disconnect;
111+
- (void) disconnectForced;
111112

112113
- (void) sendMessage:(NSString *)data;
113114
- (void) sendMessage:(NSString *)data withAcknowledge:(SocketIOCallback)function;

SocketIO.m

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,25 @@ - (void) disconnect
165165
}
166166
}
167167

168+
- (void) disconnectForced
169+
{
170+
NSString *protocol = [self useSecure] ? @"https" : @"http";
171+
NSString *urlString = [NSString stringWithFormat:@"%@://%@:%i/socket.io/1/xhr-polling/%@?disconnect", protocol, _host, _port, _sid];
172+
NSURL *url = [NSURL URLWithString:urlString];
173+
174+
NSURLRequest *request = [NSURLRequest requestWithURL:url];
175+
NSError *error = nil;
176+
NSHTTPURLResponse *response = nil;
177+
178+
[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
179+
180+
if(error || [response statusCode] != 200) {
181+
DEBUGLOG(@"Error during disconnect: %@", error);
182+
}
183+
184+
[self onDisconnect:error];
185+
}
186+
168187
- (void) sendMessage:(NSString *)data
169188
{
170189
[self sendMessage:data withAcknowledge:nil];

0 commit comments

Comments
 (0)