gimite / web-socket-js

HTML5 Web Socket implementation powered by Flash
BSD 3-Clause "New" or "Revised" License
2.73k stars 489 forks source link

web-socket-js and Jetty 8.0 #71

Closed alexander-schulze closed 13 years ago

alexander-schulze commented 13 years ago

Hi Hiroshi Ichikawa,

we are using your latest Version of the web_socket.js flashbridge for jWebSocket which works perfectly - thanks for this great piece of software - except in combination with Jetty 8. We know, Jetty has a problem when opening a websocket connection immediately after the page has finished loading, so we modified your sample.html and added a button to open the connection after a while. It works for all our engines except Jetty 8. Firebug states an IO/Error error. Unfortunately these are all details I can give (from Firebug console):

[WebSocket] policy file: xmlsocket://localhost:843 [WebSocket] cannot connect to Web Socket server at ws://localhost:80/jWebSocket/jWebSocket (IoError) console.error(decodeURIComponent(message)); web_socket.js (Zeile 303) [WebSocket] close

The policy file is send and accepted. I suspect there is some mismtach going on with the protocol versions. The issue is not limited to firefox, it's also happening on IE and all older browser versions when trying to connect to Jetty. Jetty is working perfectly with FF4 (with activated WebSockets), Chrome, Safari and Opera 11. Before we go into details, did you test web-socket-js against Jetty 8 already? If not, are you planning to do that and if so how is your schedule?

Don't hesitate to contact me in case of any questions.

Thanks in advance for your support.

Best Regards Alex, a.schulze@jWebSocket.org

gimite commented 13 years ago

Before we go into details, did you test web-socket-js against Jetty 8 already? If not, are you planning to do that and if so how is your schedule?

No, I haven't tested it with Jetty 8, and I don't have plan to do that for now. You can see "Troubleshooting" section of README at https://github.com/gimite/web-socket-js to debug further. Please let me know if you find how to fix it.

alexander-schulze commented 13 years ago

Hi Hiroshi Ichikawa,

I had a look into the trouble shooting section and I turned on the WEB_SOCKET_DEBUG = true; switch. This is what I get when I try to connect to Jetty 8 using the latest web_socket_js.

[WebSocket] policy file: xmlsocket://localhost:843 [WebSocket] cannot connect to Web Socket server at ws://localhost:80/jWebSocket/jWebSocket (IoError) [WebSocket] close

Connecting to all our other other engines works fine, like you can see here:

[WebSocket] policy file: xmlsocket://localhost:843 [WebSocket] connected [WebSocket] request header: GET /jWebSocket/jWebSocket HTTP/1.1 Upgrade: WebSocket Connection: Upgrade Host: localhost:8787 Origin: http://localhost Cookie: Sec-WebSocket-Key1: 29 P1@0 6 x98=8p12 Sec-WebSocket-Key2: 316B0o 4 7 9; 6 M 0/ Sec-WebSocket-Protocol: jwebsocket.org/json [WebSocket] sent key3: ÔM%í$EIÓ [WebSocket] response header: HTTP/1.1 101 WebSocket Protocol Handshake Upgrade: WebSocket Connection: Upgrade Sec-WebSocket-Protocol: jwebsocket.org/json Sec-WebSocket-Origin: http://localhost Sec-WebSocket-Location: ws://localhost:8787/jWebSocket/jWebSocket [WebSocket] reply digest: 50uf€†ÆUá¬3Aß [WebSocket] received: {"ns":"org.jwebsocket.plugins.system","vendor":"jWebSocket.org","type":"welcome","timeout":0,"sourceId":"01.50794","usid":"7e52930cf3322ea93ba031b5e28f34c1","version":"1.0a10 (build 10516)"}

Since Jetty as a popular Servlet Container provides a WebSocketServlet this might become interesting for you to check. I suspect it's just a WebSocket protocol version mismatch. BTW, all other Browsers, like Chrome 10, Opera 11 (WS support turned on), Safari 5 and Firefox 4 (WS support turned on) do not have any problems with Jetty 8. The problem seems limited to web_socket_js and Jetty 8. I would appreciate your feedback once you have tested web_socket_js against Jetty 8.

Thanks in advance.

Alex jWebSocket.org

kanaka commented 13 years ago

@jWebSocket, it looks to me like something is going wrong with loading the policy file. The "policy file:" message is printed before the policy request is sent. The "connected" message is issued when the a socket is established with the server but before the WebSockets handshake has started. So the error you are seeing is after the policy request happens but before a socket connection to the main port has been successfully established. That makes me think the policy request is where the failure is happening. Do you have a policy server running on port 843. Or alternately, if Flash gets a RESET from 843 then it will issue the policy request to the main port instead. Several WebSockets servers are designed to detect and answer policy requests on the same port (Socket.IO, websockify).

alexander-schulze commented 13 years ago

Hi Kanaka,

thanks for your feedback. Yes, we have a policy request listener running in jWebSocket which listens on port 843. Once a policy file request comes in we answer with a crossdomain,xml, default is:

< ?xml version="1.0"? > < !DOCTYPE cross-domain-policy SYSTEM "/xml/dtds/cross-domain-policy.dtd" > < cross-domain-policy > < allow-access-from domain="" to-ports="" / > < /cross-domain-policy >

(I had to insert spaces after < and before > to show the XML here, these spaces, of course, are not part of the crossdomain.xml)

To me it does not look like an issue in the policy file. Only the first of the two examples I sent above shows the issue, the second one shows how it works properly. The process we use is as follows: Wait for policy file request on 843 and answer it immediately. This works fine and runs within a separate process, i.e. completely independent from the engine (jetty, netty, glassfish our own one).

AFTER the policy file request has been answered properly, which I assume to see in the working example, web_socket_js tries to connect to the websocket server on port 80. And this fails, as mentioned on Jetty only.

I read your feedback various times but I cannot see a hint that "The "policy file:" message is printed BEFORE the policy request is sent." Can you explain that? Is it possible that you accidentally mixed up the second (working) log output with the above (error) log output? However, I think you are right, I also assume that the error happens AFTER the policy file request has been answered and WHILE web_socket_js tries to establish the websocket connection to port 80. Is there a way to debug more granually?

Since Jetty is setup quickly, may be you could do us a favor and try it on your side? This would help as a lot and we would be very thankful.

Thanks in advance for your support. Alex (jWebSocket.org)

gimite commented 13 years ago

Another possibility is that simply the TCP connection to localhost:80 fails. This may be more likely than socket policy issue because it's IoError, not SecurityError. Some possible reasons I can think of :

I agree with @kanaka that the error is probably before sending WebSocket request (per log), so communication in WebSocket layer (such as WebSocket version) is probably not the cause.

alexander-schulze commented 13 years ago

Hi gimite,

good catch! Using the IP4 number fixed the issue! Thanks a lot! This is what we get now with FF4 (see below FYI). So it was a IP4/IP6 issue. Thanks again for your support.

Best Regards Alex

[WebSocket] policy file: xmlsocket://127.0.0.1:843 [WebSocket] connected [WebSocket] request header: GET /jWebSocket/jWebSocket HTTP/1.1 Upgrade: WebSocket Connection: Upgrade Host: 127.0.0.1 Origin: http://127.0.0.1 Cookie: Sec-WebSocket-Key1: 23 423; R261e4 0 ;r Sec-WebSocket-Key2: 612 u0 .; !p1v & 9?jaD 3<41 Sec-WebSocket-Protocol: jwebsocket.org/json [WebSocket] sent key3: =î‚FS‡ × [WebSocket] response header: HTTP/1.1 101 WebSocket Protocol Handshake Upgrade: WebSocket Connection: Upgrade Sec-WebSocket-Origin: http://127.0.0.1 Sec-WebSocket-Location: ws://127.0.0.1/jWebSocket/jWebSocket Sec-WebSocket-Protocol: jwebsocket.org/json [WebSocket] reply digest: ôØRm^»ÙŽkŒª´Ÿ [WebSocket] received: {"ns":"org.jwebsocket.plugins.system","vendor":"jWebSocket.org","type":"welcome","timeout":0,"sourceId":"01.55372","usid":"af834d30e214766003470cae17ef8a24","version":"1.0a10 (build 10516)"}

kanaka commented 13 years ago

I read your feedback various times but I cannot see a hint that "The "policy file:" message is printed BEFORE the policy request is sent." Can you explain that?

I looked in the source and was just describing the code flow and comparing it to both outputs.

Glad you figured it out.