ianharrigan / hxWebSockets

hxWebSockets - websockets for all haxe platforms
https://github.com/ianharrigan/hxWebSockets
81 stars 18 forks source link

426 Upgrade required error #32

Open haath opened 3 years ago

haath commented 3 years ago

Hello, I am using an hxWebSockets server behind an apache proxy. I am trying to access it through normal js websockets on a browser, but it seems like the connection fails at the stage where the protocol should be upgraded to a websocket.

image

It seems like the request is reaching the backend server, because the following appears in the logs:

INFO  :: Starting server - 0.0.0.0:8000 (maxConnections: 100)
DEBUG :: ID-1 :: New socket handler
DEBUG :: ID-1 :: Adding to web server handler to list - total: 1
DEBUG :: ID-1 :: Bytes read: 641
DEBUG :: ID-1 :: Closed
DEBUG :: ID-1 :: Removing web server handler from list - total: 0

So the websocket server is closing the connection without returning the proper upgrade headers?

Is this something that can be fixed on the side of this library? Or could you recommend some apache config where it should work?

ianharrigan commented 3 years ago

Im not sure what apache config might help... have you tried running it without a proxy? Is it fine then? Also, when haxe target is the server running on?

Cheers, Ian

haath commented 3 years ago

Hey thanks for the response! The target in this case is cpp, but I could try others if you think it makes a difference.

Without a proxy everything works with insecure ws://. My issue is browsers require secure websockets when the page is loaded over https:// so my go-to method is to use a proxy because I manage all of my certificates on apache.

I could also try using WebSocketSecureServer but then my server only has one 443 port and apache is using it. 😄 And some browsers also don't like non-standard ports for SSL connections.

haath commented 3 years ago

Ok so I tried it with WebSocketSecureServer on a nonstandard port, with valid certificates. Now I try to connect to it directly without a proxy, and Firefox gives the following error:

main.js:1218 WebSocket connection to 'wss://xxxxxx:8000/' failed:

And on the server side I get the following.

INFO  :: Starting server - 0.0.0.0:8000 (maxConnections: 100)
DEBUG :: ID-1 :: New socket handler
DEBUG :: ID-1 :: Adding to web server handler to list - total: 1
DEBUG :: ID-1 :: Closed
DEBUG :: ID-1 :: Removing web server handler from list - total: 0
DEBUG :: ID-2 :: New socket handler
DEBUG :: ID-2 :: Adding to web server handler to list - total: 1
DEBUG :: ID-2 :: Closed
DEBUG :: ID-2 :: Removing web server handler from list - total: 0
ianharrigan commented 3 years ago

Hmm, so it looks like it closes the connection instantly... i wonder if the client (FF) is doing that? Does chrome behave differently? What about a non "non standard" port? :)