Socket.IO-Client-Swift icon indicating copy to clipboard operation
Socket.IO-Client-Swift copied to clipboard

Using socket.io-client on port 443

Open cdagli opened this issue 10 years ago • 19 comments

Hello,

Should we set any extra option to use this client with port 443? An example would be great.

I was using https://github.com/pkyeck/socket.IO-objc before with socket.io 0.9 and https was working okay but I couldn't make it work with this implementation. Port 80 works okay.

Thank you.

cdagli avatar May 02 '15 21:05 cdagli

let socket = SocketIOClient(socketURL: "https://localhost:443")

Should use TLS

nuclearace avatar May 02 '15 21:05 nuclearace

Cool, it works. I've added the https:// part.

Thank you!

cdagli avatar May 02 '15 21:05 cdagli

Doesn't seem to be working with objective C?

icykey avatar Jul 26 '15 05:07 icykey

how do I get pass the SSL error on local server? NSURLConnection/CFURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9843)

icykey avatar Jul 26 '15 05:07 icykey

How are you creating the client?

nuclearace avatar Jul 26 '15 13:07 nuclearace

self.socket = [[SocketIOClient alloc] initWithSocketURL:@"https://localhost:443" options:params]; I am running the server locally, with the real certificates, so it fails validation on domain not matching. I guess my question is , is there an easy way to set the option to ignore certificate validation. Like AFNetworking has this flag #ifdef AFNETWORKING_ALLOW_INVALID_SSL_CERTIFICATES What is the best way, if i just want to run and debug my server locally. thanks!

icykey avatar Jul 26 '15 14:07 icykey

I'll see about making this easier to work with.

nuclearace avatar Jul 26 '15 19:07 nuclearace

Thank you! I did try using the sessionDelegate option, [parameter setObject:self forKey:@"sessionDelegate"];

- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential *credential))completionHandler
{
    completionHandler(NSURLSessionAuthChallengeUseCredential, [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust]);
}

I was able to by pass the SSL certificate check, however cookies are not working after connection, I am not able to set cookies in which was set in a pervious (login api) response, (socket.request.headers.cookie). I think I may need to implement more in the NSURLSessionDataDelegate methods in order to do that? I am not sure how to do that yet...

icykey avatar Jul 26 '15 22:07 icykey

This may be off topic, but while working with sessionDelegate option... in order to support global cache, cookie and credential storage objects. The NSURLSession Configuration needs to be created with defaultSessionConfiguration.

in SocketEngine.swift

    self.session = NSURLSession(configuration: NSURLSessionConfiguration.ephemeralSessionConfiguration(),
        delegate: sessionDelegate, delegateQueue: workQueue)

I had to change ephemeralSessionConfiguration to defaultSessionConfiguration for server to authenticate cached cookie... Is there a reason to use ephemeralSessionConfiguration there? so it is always 'private' session and has no persistent storage for cache? more secure? Maybe open this up as an option too?

icykey avatar Jul 26 '15 23:07 icykey

The reason is used an ephemeral session is because I didn't think there's a reason to do any disk caching for cookies

nuclearace avatar Jul 27 '15 22:07 nuclearace

Also, I'm not really seeing an easier way of doing it then allowing specifying a delegate.

nuclearace avatar Jul 27 '15 22:07 nuclearace

In my application, user authentication happens separate from "socket connect", with defaultSessionConfiguration I am able to rely on the cached cookie to authenticate user on socket connection. Same as the "keep me logged in" feature of the web services apis... With this, I am then forced to manually manage cookie and pass it on socket connect?

icykey avatar Jul 27 '15 22:07 icykey

I guess I can change it to default.

nuclearace avatar Jul 27 '15 22:07 nuclearace

Should be updated in master branch

nuclearace avatar Jul 27 '15 22:07 nuclearace

Thank you!

icykey avatar Jul 27 '15 23:07 icykey

In that regard: We also need to be able to access a session cookie we receive from the server upon login/first connection. Any ideas on how/where we can access that cookie?

Once we have the cookie, I suppose we can present it to the server in future requests via the "cookies:" option of connectParams.

But how do we get hold of the cookie in the first place? Maybe by making use of the sessionDelegate: option, but haven't figured it out yet. Any ideas are highly appreciated!

markschmid avatar Aug 14 '15 15:08 markschmid

Probably from adding a sessionDelegate only if you're not forcing WebSocket. Otherwise I think it'd get complicated and I'd have to add in more functionality.

nuclearace avatar Aug 14 '15 17:08 nuclearace

Hi, I'm trying to create a cocoa pod library that use socket connection, I want to use this library but is on swift, do you have an Objective c version that I can use???? Thanks!!

cesar-oyarzun-m avatar Sep 01 '15 17:09 cesar-oyarzun-m

You can use Swift code in Objective-C projects. https://developer.apple.com/library/ios/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html

nuclearace avatar Sep 01 '15 18:09 nuclearace