Open katsuo555 opened 9 years ago
I use it in the connection block:
NSDictionary * parameters = [NSDictionary dictionaryWithObject:token forKey:@"token"];
NSArray * parametersArray = [NSArray arrayWithObject:parameters];
[SIOSocket socketWithHost:serverURL response: ^(SIOSocket *socket){
self.socket = socket;
self.socket.onConnect = ^ () {
if ([GabAuthenticatedUser sharedUser].token) {
NSLog(@"SIOSocket : web socket connected. Authenticating with parameters : %@", parameters);
[socket emit: @"authenticate" args:parametersArray];
}
};
self.socket.onDisconnect = ^ () {
NSLog(@"SIOSocket : web socket disconnected!");
};
self.socket.onError = ^(NSDictionary* error) {
NSLog(@"SIOSocket : error connecting to web socket : %@", error);
};
}];
An even more straightforward method that I personally used:
NSString *url = [NSString stringWithFormat:@"http://localhost:3000?token=%@",token];
[SIOSocket socketWithHost: url response: ^(SIOSocket *socketer) {
...
Works like a charm!
I am developing a application of two-way communication in SocketIO between App of iPhone and server.
I would like to implement the authentication function when connecting from the application side to the chat server.
I have implemented on the server side as described below.
However, I do not know where I should set the token in the app side.
To borrow your wisdom.