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

Commit bc83082

Browse files
Synchronous disconnect
1 parent 79fac8e commit bc83082

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-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) disconnectSync;
111112

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

SocketIO.m

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

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

0 commit comments

Comments
 (0)