gimite / web-socket-js

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

Serving the policy with the HTTP server #152

Closed sprat closed 10 years ago

sprat commented 10 years ago

Hello,

I'm trying to serve the flash policy from my HTTP server (i.e. same host/port as the websocket) instead of a TCP server on port 843, but I can't get it to work.

Reading the flash security documents, it seems that, when you try to open a socket on xmlsocket://localhost:8080/ws, Flash first try to find a policy file on xmlsocket://localhost:843, then fallback to xmlsocket://localhost:8080 after 3 seconds. So, in theory, if I can serve the xmlsocket request in my HTTP server, it should work.

I've implemented a special case in my HTTP server to handle this non-HTTP request and return the policy file, with a trailing 0 at the end of the response. I can see from the HTTP server logs that Flash send it's policy request and that my server send it's response. I've also checked with telnet that I receive the proper policy response when I send the XML request to my HTTP server. But, the websocket doesn't start, it seems to timeout.

I've also tried to use the WebSocket.loadFlashPolicyFile function to issue either a xml request on xmlsocket://localhost:8080 or an HTTP request to http://localhost:8080/crossdomain.xml but it does not work either.

Is there's something preventing what I'm trying to achieve in the flash websocket implementation?

How can I troubleshoot this problem? I've tried with IE 9, Chrome and Firefox (with window.WEB_SOCKET_FORCE_FLASH set), without any success. I've installed the debug version of flash and FlashFirebug on Firefox, but I don't see anything wrong in the policy log. What am I missing? Are there better debug tools?

OK: Chargement du fichier SWF au niveau racine : http://127.0.0.1:8080/flashwebsocket/WebSocketMain.swf OK: Recherche de dans les fichiers de régulation pour autoriser le chargement des données depuis la ressource à xmlsocket://127.0.0.1:8080 par le demandeur de http://127.0.0.1:8080/flashwebsocket/WebSocketMain.swf

Can you please help? Thanks in advance, Sylvain

gimite commented 10 years ago

Do you disconnect TCP connection after sending socket policy XML? I vaguely remember that it doesn't work if the server doesn't disconnect the connection.

sprat commented 10 years ago

I close the socket just after sending the response. And I didn't forget the terminal 0 (not sure if it is needed or not).

Regarding the socket policy, I've nearly the same code between my TCPServer implementation on port 843 (which works) and my HTTP server on port 8080 (which doesn't work), that's why I am wondering what's wrong here.

I am pretty sure my HTTP server code is ok. To confirm that (I just had the idea), I'll try to launch my HTTP server also on port 843 and see if the policy is received and I'll report the result here.

sprat commented 10 years ago

OK, I've just checked with an instance of the HTTP server bound on port 843 to serve the policy and it does not work. So, the problem lies in my code for sure! But I still have no idea what am I missing...

sprat commented 10 years ago

OK, I found out the problem. The response is sent after the timeout delay, that's why it does not work. Sorry for the false bug report, I'm closing the issue.