socket.io-client-swift icon indicating copy to clipboard operation
socket.io-client-swift copied to clipboard

https self signed connect problem

Open kennyiproperty opened this issue 10 years ago • 8 comments

Hi,

My problem is trying to connect to a self signed SSL URL with the following code using a custom path:-

NSURL* url = [[NSURL alloc] initWithString:@"https://test.com/chat"];
SocketIOClient *socket = [[SocketIOClient alloc] initWithSocketURL:url options:@{@"log":@YES, @"forcePolling":@YES, @"path":@"/testsocket/socket.io", @"selfSigned":@YES, @"sessionDelegate":self}];

[socket on:@"connect" callback:^(NSArray* data, SocketAckEmitter* ack) {
    NSLog(@"socket connected");
}]; 
[socket connect];

The error I'm getting is

LOG SocketEngine: Got message: Cannot GET /socket.io?transport=polling&b64=1.

Does anyone know how to solve this issue? Without SSL it works fine and I also used the SessionDelegate. Basically the socket connected never gets fired. Thanks very much for the help.

kennyiproperty avatar Jun 03 '16 11:06 kennyiproperty

Are you implementing the appropriate SessionDelegate method that handles SSL challenges?

nuclearace avatar Jun 03 '16 14:06 nuclearace

hi,

This is what I did, is there something extra still needed? Thank you.

- (void)URLSession:(NSURLSession *)session didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential * _Nullable))completionHandler {
    NSLog(@"test");

    completionHandler(NSURLSessionAuthChallengeUseCredential, [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust]);
}

kennyiproperty avatar Jun 04 '16 01:06 kennyiproperty

Is your URL the same for the non-ssl one? Just with https? Maybe your url is wrong.

nuclearace avatar Jun 05 '16 14:06 nuclearace

the url is different but i'm suspecting it's with this I'm getting. I notice for successful connections sid is passing something over but for the failed connection sid is nil. Does the sid need to have something for it to connect successfully? Thank you very much for the help.

https://test.com/chatsocket/socket.io?transport=polling&b64=1&sid=

kennyiproperty avatar Jun 06 '16 09:06 kennyiproperty

ok I have figured out the issue. What was happening is that the @"path":@"/testsocket/socket.io" parameter style for the ios library is different from the web version. The iOS needed an extra "/" at the end. So the error was because the end URL is incorrect. This is now resolved and thanks very much for the help!

kennyiproperty avatar Jun 07 '16 10:06 kennyiproperty

I am using this library in obj-c project, everything was working great before I turned my server to https. At the moment I turned to https I was encountering invalid certificate issue which I had addressed by implementing didReceiveChallenge delegate method. Now, I am getting this error ;

Cannot GET /socket.io/?transport=polling&b64=1 socket = [[SocketIOClient alloc] initWithSocketURL:[[NSURL alloc] initWithString:@"https://localhost:xxxx"] config:@{@"log": @YES, @"forcePolling": @YES, @"selfSigned": @YES, @"sessionDelegate":appDelegate}];

I have also given a try by placing following key and value in config. @"path":@"/node_modules/socket.io"

Any prompt help will be really appreciated.

githubforIT avatar Mar 02 '17 13:03 githubforIT

Thanks, I have resolved myself.

githubforIT avatar Mar 03 '17 05:03 githubforIT

@githubforIT How did you resolve it? I am facing same issue. I appreciate if you can share your solution. Regards!

bbdroid avatar Jul 06 '18 05:07 bbdroid