• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..--

README.txtD22-Nov-20235.8 KiB11065

WebSocketMain.swfD22-Nov-2023173 KiB

swfobject.jsD22-Nov-202310 KiB41

web_socket.jsD22-Nov-202312.7 KiB392258

README.txt

1* How to try
2
3Assuming you have Web server (e.g. Apache) running at http://example.com/ .
4
5- Download web_socket.rb from:
6  http://github.com/gimite/web-socket-ruby/tree/master
7- Run sample Web Socket server (echo server) in example.com with: (#1)
8  $ ruby web-socket-ruby/samples/echo_server.rb example.com 10081
9- If your server already provides socket policy file at port 843, modify the file to allow access to port 10081. Otherwise you can skip this step. See below for details.
10- Publish the web-socket-js directory with your Web server (e.g. put it in ~/public_html).
11- Change ws://localhost:10081 to ws://example.com:10081 in sample.html.
12- Open sample.html in your browser.
13- After "onopen" is shown, input something, click [Send] and confirm echo back.
14
15#1: First argument of echo_server.rb means that it accepts Web Socket connection from HTML pages in example.com.
16
17
18* Troubleshooting
19
20If it doesn't work, try these:
21
221. Try Chrome and Firefox 3.x.
23- It doesn't work on Chrome:
24-- It's likely an issue of your code or the server. Debug your code as usual e.g. using console.log.
25- It works on Chrome but it doesn't work on Firefox:
26-- It's likely an issue of web-socket-js specific configuration (e.g. 3 and 4 below).
27- It works on both Chrome and Firefox, but it doesn't work on your browser:
28-- Check "Supported environment" section below. Your browser may not be supported by web-socket-js.
29
302. Add this line before your code:
31  WEB_SOCKET_DEBUG = true;
32and use Developer Tools (Chrome/Safari) or Firebug (Firefox) to see if console.log outputs any errors.
33
343. Make sure you do NOT open your HTML page as local file e.g. file:///.../sample.html. web-socket-js doesn't work on local file. Open it via Web server e.g. http:///.../sample.html.
35
364. If you are NOT using web-socket-ruby as your WebSocket server, you need to place Flash socket policy file on your server. See "Flash socket policy file" section below for details.
37
385. Check if sample.html bundled with web-socket-js works.
39
406. Make sure the port used for WebSocket (10081 in example above) is not blocked by your server/client's firewall.
41
427. Install debugger version of Flash Player available here to see Flash errors:
43http://www.adobe.com/support/flashplayer/downloads.html
44
45
46* Supported environments
47
48It should work on:
49- Google Chrome 4 or later (just uses native implementation)
50- Firefox 3.x, Internet Explorer 8 + Flash Player 9 or later
51
52It 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.
53
54
55* Flash socket policy file
56
57This implementation uses Flash's socket, which means that your server must provide Flash socket policy file to declare the server accepts connections from Flash.
58
59If you use web-socket-ruby available at
60http://github.com/gimite/web-socket-ruby/tree/master
61, you don't need anything special, because web-socket-ruby handles 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 web-socket-ruby provides.
62
63If you use other Web Socket server implementation, you need to provide socket policy file yourself. See
64http://www.lightsphere.com/dev/articles/flash_socket_policy.html
65for details and sample script to run socket policy file server. node.js implementation is available here:
66http://github.com/LearnBoost/Socket.IO-node/blob/master/lib/socket.io/transports/flashsocket.js
67
68Actually, it's still better to provide socket policy file at port 843 even if you use web-socket-ruby. Flash always try to connect to port 843 first, so providing the file at port 843 makes startup faster.
69
70
71* Cookie considerations
72
73Cookie is sent if Web Socket host is the same as the origin of JavaScript. 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).
74
75Note 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.
76
77
78* Proxy considerations
79
80The WebSocket spec (http://tools.ietf.org/html/draft-hixie-thewebsocketprotocol) specifies instructions for User Agents to support proxied connections by implementing the HTTP CONNECT method.
81
82The 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.
83
84The 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.
85
86
87* How to host HTML file and SWF file in different domains
88
89By default, HTML file and SWF file must be in the same domain. You can follow steps below to allow hosting them in different domain.
90
91WARNING: 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.
92
93- Unzip WebSocketMainInsecure.zip to extract WebSocketMainInsecure.swf.
94- Put WebSocketMainInsecure.swf on your server, instead of WebSocketMain.swf.
95- In JavaScript, set WEB_SOCKET_SWF_LOCATION to URL of your WebSocketMainInsecure.swf.
96
97
98* How to build WebSocketMain.swf
99
100Install Flex 4 SDK:
101http://opensource.adobe.com/wiki/display/flexsdk/Download+Flex+4
102
103$ cd flash-src
104$ ./build.sh
105
106
107* License
108
109New BSD License.
110