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

Flash fallback doesn't work in Firefox 3.6/OS X #4

Closed ithinkihaveacat closed 14 years ago

ithinkihaveacat commented 14 years ago

I've been trying to follow the instructions in README.txt to get the Flash fallback implentation of WebSockets in Firefox 3.6/OS X, but it does not appear to work. If I download web-socket-ruby and then run the echo server with

$ sudo ruby samples/echo_server.rb beebo.local 10081
Server is running at port 10081

then change sample.html WebSocket connect line to

ws = new WebSocket("ws://beebo.local:10081/");

then connections are made as expected in Chrome, and log messages on the client and server show messages being passed back and forth. However, in Firefox nothing happens. WebSocketMain.swf is loaded, but apart from that, none of the socket stuff appears to work. e.g. no attempt appears to be made to load a policy file, nothing appears on the server. I downloaded an installed the debug version of the Flash player, but that doesn't seem to to anything beyond the regular player. How can I activate "debug" mode?

gimite commented 14 years ago

Debug version of the player pops up dialog when Flash error happens. Some hints:

TooTallNate commented 14 years ago

And just for the record, I just tested on OSX/Firefox 3.6 and it works as expected. I'm using my Java WebSocket server to test with, not the Ruby one, but it's more likely something wrong in your setup.

Firstly, are you running the sample.html file from a file:/// URI? That is allowed, you just need to add the path of the SWF file to Flash's Global Security settings first.

ithinkihaveacat commented 14 years ago

Finally figured it out! The WebSocketMain.swf was being served, but in some strange encoding (I'm using a sort of homebrew NodeJS webserver, and it had only ever served text before, so I didn't notice). This broke the Flash file itself, which died silently.

Thanks for your help!

afshinm commented 14 years ago

Hi,

I'm using websocket.js and it worked good in Chrome but in Firefox and IE, WebSocket object created but it not connected to server ...

When i start FireBug, i see some errors:

[WebSocket] cannot connect to Web Socket server at ws://localhost:12345/ (SecurityError) make sure the server is running and Flash socket policy file is correctly placed webSocketError(Object { name="message"})web_socket.js (line 311) [Break on this error] console.error(decodeURIComponent(message));\n

Whats the problem?

Thanks.

gimite commented 14 years ago

Did you place Flash socket policy file in your server? See "Flash socket policy file" section of http://github.com/gimite/web-socket-js .

afshinm commented 14 years ago

Dear gimite, I read it and i try to do that but i can't, i use PHP Server, can you please help me to place Flash socket policy files?

gimite commented 14 years ago

Easiest way would be to run Perl script introduced at: http://www.lightsphere.com/dev/articles/flash_socket_policy.html in your server (referred in the "Flash socket policy file" section).

afshinm commented 14 years ago

Thanks dear gimite but i can't work with Perl, can i do this with PHP? Is there any source for this?

Thanks.

afshinm commented 14 years ago

Hi again,

I put Flash socket policy file with Python and works good but after this step i get this error:

[WebSocket] cannot connect to Web Socket server at ws://localhost:1234/ (IoError) [Break on this error] console.error(decodeURIComponent(message));\n

Whats the problem? Thanks.

gimite commented 14 years ago

It's most likely that the Web Socket server is not accessible. Does it really work fine with Chrome with same Web Socket URL still? Also your original email shows that you specified ws://localhost:12345/ but now it looks you specify ws://localhost:1234/ . Are you OK with that?

afshinm commented 14 years ago

Yes, it works in Chrome with ws://localhost:12345/ but with same URL it have problem with Firefox and IE. May this error show because the Client and Server is the same?

gimite commented 14 years ago

It should be OK if client and server is in the same host. But it doesn't work when you open the html file as local file i.e. file:///.../sample.html. Please open it via Web server. If you open it with http://... already, I have no idea...

afshinm commented 14 years ago

Thanks you dear gimite, it worked but now i have another problem. When i start my WebSocket server and start Flash Policy file server, it try to connect to WebSocket server but connection not established and i can't send my messages to server. Here my headers:

[WebSocket] policy file: xmlsocket://172.16.17.211:843 [WebSocket] connected [WebSocket] request header: GET / HTTP/1.1 Upgrade: WebSocket Connection: Upgrade Host: 172.16.17.211:8181 Origin: http://172.16.17.211 Cookie: PHPSESSID=eab33c48b3a1ab91d746f5268af223ec Sec-WebSocket-Key1: ;2 203 2 2130C 0 Sec-WebSocket-Key2: 4v 4 7 1 12 85_0 [WebSocket] sent key3: 8K<ðïÇ{~ [WebSocket] response header: HTTP/1.1 101 Web Socket Protocol Handshake Upgrade: WebSocket Connection: Upgrade WebSocket-Origin: http://172.16.17.211 WebSocket-Location: ws://172.16.17.211:8181/

When i try to send a message to server i see this error: INVALID_STATE_ERR: Web Socket connection has not been established

And also WebServer show me that some body connected to server. It worked in Safari and Chrome but in other browsers like FireFox nd IE i have this problem.

Thank you.

gimite commented 14 years ago

Looks like your Web Socket server doesn't support new protocol. Web Socket protocol recently changed and web-socket-js follows new protocol. What Web Socket server are you using? Latest version of web-socket-ruby and em-web-socket supports new protocol. You should check if the server you are using has newer version supporting new protocol. In new protocol, server's response header includes "Sec-WebSocket-Origin" and "Sec-WebSocket-Location" instead of "WebSocket-Origin" and "WebSocket-Location".

afshinm commented 14 years ago

Yes, true. When i change the Header to "Sec-..." i see nothing, web server also don't work with Firefox and IE, but in Safari i have no error.

afshinm commented 14 years ago

Also when i change headers to "Sec-..." after a few second i get this error: [WebSocket] digest doesn't match: �server: other d != 3dAÀCá ÎiÀז$¾C

gimite commented 14 years ago

Yeah the protocol update is not only about the header name. It also adds some security token exchange. If you use WebSocket server publicly available (e.g. em-websocket), it's likely that its latest version supports new protocol. If you implemented WebSocket server yourself, you should support new protocol yourself... See spec for details: http://tools.ietf.org/html/draft-hixie-thewebsocketprotocol-76

afshinm commented 14 years ago

Thank you dear gimite. My WebSocket server based on .NET (and also in PHP) so how can i upgrade my protocol? Is there any tutorial for this?

gimite commented 14 years ago

I don't see any useful information other than the original spec: http://tools.ietf.org/html/draft-hixie-thewebsocketprotocol-76 It might be useful to read source code of other WebSocket servers. e.g. If you can read Ruby, http://github.com/gimite/web-socket-ruby/blob/master/lib/web_socket.rb might be useful.