nuclearace / Socket.IO-Client-Swift

socket.io-client for Swift
Other
361 stars 53 forks source link

Socket Disconnected #126

Closed ivanornes closed 7 years ago

ivanornes commented 8 years ago

I have a node server behind a proxy and I can connect to node's socket with Chrome's Simple WebSocket client and through an iOS simple SocketRocket client, but not with the Socket.IO swift client. The connection ends with an NSStream end encountered event (NSStreamEventEndEncountered)

I have tested it in from the 5.0.0 version up to the 6.1.2 and the last development branch.

nuclearace commented 8 years ago

If you want to connect directly to your server with WebSockets then do

let socket = SocketIOClient(url: NSURL(string: "http://myserver.com/")!, options: [.ForceWebsockets(true)])

Or the obj-c equivalent.

ivanornes commented 8 years ago

I have tried all the protocols, ws, wss, http, https with the same result.

nuclearace commented 8 years ago

What version of socket.io is the server using?

ivanornes commented 8 years ago

1.4.6

nuclearace commented 8 years ago

Are your url and ports correct? Because I've tested just plain socket.io servers and Forcewebsockets and it works fine.

ivanornes commented 8 years ago

we have a haproxy redirecting the traffic just for one node instance, does the library check the responses of the server?

nuclearace commented 8 years ago

You may have to connect directly to the server, I have never tested proxy stuff. I don't think the WebSocket library supports SOCKS atm. But there's a pull request that is looking to add it.

ivanornes commented 8 years ago

I have just check the javascript, react-native socket.io and the Android clients and all work ok

nuclearace commented 8 years ago

You could probably not force websockets. Since I would think NSUSRLSession would be able to handle proxy stuff.

nuclearace commented 8 years ago

https://github.com/daltoniam/Starscream/pull/202

ivanornes commented 8 years ago

Without forcing seems like uses polling all the time, and at some point I get the session ID unknown Got message: {"code":1,"message":"Session ID unknown"}

nuclearace commented 8 years ago

Correct, because it can't connect the websocket because of the proxy. That's why socket.io uses polling before it switches to Websockets. As for the unknown session ID, I have no idea about that. That shouldn't happen if the request is going to the same socket.io server and the connection hasn't been closed.

nuclearace commented 8 years ago

If you must have Websockets then you might have to connect directly to your server, bypassing the proxy.

ivanornes commented 8 years ago

I can't do that, and the strange thing is that with the javascript and Android clients just work.

nuclearace commented 8 years ago

They both use Websocket libraries that support SOCKS proxies I assume. You'll have to wait for the above pull request to be merged. And then I'll update the websocket library here.

ivanornes commented 8 years ago

I tried oldshuren's proxy-connect repo with the proxy fix and doesn't seem to work

ivanornes commented 8 years ago

I will try to use a react-native view as a workaround to this problem, I don´t know if the issue is in the client library or in the haproxy config

nuclearace commented 8 years ago

Well your url in the screenshot for the WebSocket example is wrong. It'd have to be the same as in SocketRocket.