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

Commit

Permalink
Add support for synchronous disconnect. close #112.
Browse files Browse the repository at this point in the history
  • Loading branch information
pkyeck committed Jul 15, 2013
2 parents 3acdb80 + bc83082 commit 29c6894
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions SocketIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ typedef enum {
- (void) connectToHost:(NSString *)host onPort:(NSInteger)port withParams:(NSDictionary *)params;
- (void) connectToHost:(NSString *)host onPort:(NSInteger)port withParams:(NSDictionary *)params withNamespace:(NSString *)endpoint;
- (void) disconnect;
- (void) disconnectForced;

- (void) sendMessage:(NSString *)data;
- (void) sendMessage:(NSString *)data withAcknowledge:(SocketIOCallback)function;
Expand Down
19 changes: 19 additions & 0 deletions SocketIO.m
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,25 @@ - (void) disconnect
}
}

- (void) disconnectForced
{
NSString *protocol = [self useSecure] ? @"https" : @"http";
NSString *urlString = [NSString stringWithFormat:@"%@://%@:%i/socket.io/1/xhr-polling/%@?disconnect", protocol, _host, _port, _sid];
NSURL *url = [NSURL URLWithString:urlString];

NSURLRequest *request = [NSURLRequest requestWithURL:url];
NSError *error = nil;
NSHTTPURLResponse *response = nil;

[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];

if(error || [response statusCode] != 200) {
DEBUGLOG(@"Error during disconnect: %@", error);
}

[self onDisconnect:error];
}

- (void) sendMessage:(NSString *)data
{
[self sendMessage:data withAcknowledge:nil];
Expand Down

0 comments on commit 29c6894

Please sign in to comment.