Recommend this page to a friend! |
Classes of Igor Escobar | Terminal Crossword | chat-websocket/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/README.md | Download |
|
|
DownloadHow to try the sampleAssuming you have Web server (e.g. Apache) running at http://example.com/ .
\#1: First argument of echo_server.rb means that it accepts Web Socket connection from HTML pages in example.com. How to use it in your application
TroubleshootingIf it doesn't work, try these:
Supported environmentsIt should work on:
It may or may not work on other browsers such as Safari, Opera or IE 6. Patch for these browsers are appreciated, but I will not work on fixing issues specific to these browsers by myself. Limitations/differences compared to native WebSocket
Flash socket policy fileThis implementation uses Flash's socket, which means that your server must provide Flash socket policy file to declare the server accepts connections from Flash. If you use web-socket-ruby or em-websocket, you don't need anything special, because they handle Flash socket policy file request. But if you already provide socket policy file at port 843, you need to modify the file to allow access to Web Socket port, because it precedes what the libraries provide. If you use other Web Socket server implementation, you need to provide socket policy file yourself. See Setting up A Flash Socket Policy File for details and sample script to run socket policy file server. node.js implementation is available here. Actually, it's still better to provide socket policy file at port 843 even if you use web-socket-ruby or em-websocket. Flash always try to connect to port 843 first, so providing the file at port 843 makes startup faster. Cookie supportweb-socket-js has limited supported for Cookies on WebSocket. Cookie is sent if Web Socket host is exactly the same as the origin of JavaScript (The port can be different). Otherwise it is not sent, because I don't know way to send right Cookie (which is Cookie of the host of Web Socket, I heard). Also, HttpOnly Cookies are not sent. Note that it's technically possible that client sends arbitrary string as Cookie and any other headers (by modifying this library for example) once you place Flash socket policy file in your server. So don't trust Cookie and other headers if you allow connection from untrusted origin. Proxy supportThe WebSocket spec specifies instructions for User Agents to support proxied connections by implementing the HTTP CONNECT method. The AS3 Socket class doesn't implement this mechanism, which renders it useless for the scenarios where the user trying to open a socket is behind a proxy. The class RFC2817Socket (by Christian Cantrell) effectively lets us implement this, as long as the proxy settings are known and provided by the interface that instantiates the WebSocket. As such, if you want to support proxied conncetions, you'll have to supply this information to the WebSocket constructor when Flash is being used. One way to go about it would be to ask the user for proxy settings information if the initial connection fails. How to host HTML file and SWF file in different domainsBy default, HTML file and SWF file must be in the same domain. You can follow steps below to allow hosting them in different domain. WARNING: If you use the method below, HTML files in ANY domains can send arbitrary TCP data to your WebSocket server, regardless of configuration in Flash socket policy file. Arbitrary TCP data means that they can even fake request headers including Origin and Cookie.
How to build WebSocketMain.swfInstall Flex 4 SDK.
WebSocket protocol versions
LicenseNew BSD License. |