| author | Raphael Velt <raph.velt@gmail.com> |
| Mon, 10 Oct 2011 15:24:28 +0200 | |
| changeset 310 | 526d3e411736 |
| parent 306 | 70c9688a1486 |
| permissions | -rw-r--r-- |
|
305
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
1 |
## How to try the sample |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
2 |
|
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
3 |
Assuming you have Web server (e.g. Apache) running at **http://example.com/** . |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
4 |
|
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
5 |
1. Download [web-socket-ruby](http://github.com/gimite/web-socket-ruby/tree/master). |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
6 |
2. Run sample Web Socket server (echo server) in example.com with: (#1)<br> |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
7 |
``` |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
8 |
$ ruby web-socket-ruby/samples/echo_server.rb example.com 10081 |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
9 |
``` |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
10 |
3. 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. |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
11 |
4. Publish the web-socket-js directory with your Web server (e.g. put it in ~/public_html). |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
12 |
5. Change ws://localhost:10081 to **ws://example.com:10081** in sample.html. |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
13 |
6. Open sample.html in your browser. |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
14 |
7. After "onopen" is shown, input something, click [Send] and confirm echo back. |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
15 |
|
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
16 |
\#1: First argument of echo_server.rb means that it accepts Web Socket connection from HTML pages in example.com. |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
17 |
|
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
18 |
|
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
19 |
## How to use it in your application |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
20 |
|
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
21 |
- Copy swfobject.js, web_socket.js, WebSocketMain.swf to your application directory. |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
22 |
- Write JavaScript code: |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
23 |
|
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
24 |
```html |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
25 |
<!-- Import JavaScript Libraries. --> |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
26 |
<script type="text/javascript" src="swfobject.js"></script> |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
27 |
<script type="text/javascript" src="web_socket.js"></script> |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
28 |
|
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
29 |
<script type="text/javascript"> |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
30 |
|
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
31 |
// Let the library know where WebSocketMain.swf is: |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
32 |
WEB_SOCKET_SWF_LOCATION = "WebSocketMain.swf"; |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
33 |
|
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
34 |
// Write your code in the same way as for native WebSocket: |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
35 |
var ws = new WebSocket("ws://example.com:10081/"); |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
36 |
ws.onopen = function() { |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
37 |
ws.send("Hello"); // Sends a message. |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
38 |
}; |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
39 |
ws.onmessage = function(e) { |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
40 |
// Receives a message. |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
41 |
alert(e.data); |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
42 |
}; |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
43 |
ws.onclose = function() { |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
44 |
alert("closed"); |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
45 |
}; |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
46 |
|
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
47 |
</script> |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
48 |
``` |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
49 |
|
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
50 |
- Put Flash socket policy file to your server unless you use web-socket-ruby or em-websocket as your WebSocket server. See "Flash socket policy file" section below for details. |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
51 |
|
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
52 |
|
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
53 |
## Troubleshooting |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
54 |
|
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
55 |
If it doesn't work, try these: |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
56 |
|
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
57 |
1. Try Chrome and Firefox 3.x. |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
58 |
|
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
59 |
- It doesn't work on Chrome:<br> |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
60 |
It's likely an issue of your code or the server. Debug your code as usual e.g. using console.log. |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
61 |
- It works on Chrome but it doesn't work on Firefox:<br> |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
62 |
It's likely an issue of web-socket-js specific configuration (e.g. 3 and 4 below). |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
63 |
- It works on both Chrome and Firefox, but it doesn't work on your browser:<br> |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
64 |
Check "Supported environment" section below. Your browser may not be supported by web-socket-js. |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
65 |
|
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
66 |
2. Add this line before your code: |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
67 |
WEB_SOCKET_DEBUG = true; |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
68 |
and use Developer Tools (Chrome/Safari) or Firebug (Firefox) to see if console.log outputs any errors. |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
69 |
|
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
70 |
3. 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. |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
71 |
|
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
72 |
4. Make sure you host your HTML page and WebSocketMain.swf in the same domain. Otherwise, see "How to host HTML file and SWF file in different domains" section. |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
73 |
|
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
74 |
5. If you are NOT using web-socket-ruby or em-websocket as your WebSocket server, you need to place Flash socket policy file on your server. See "Flash socket policy file" section below for details. |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
75 |
|
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
76 |
6. Check if sample.html bundled with web-socket-js works. |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
77 |
|
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
78 |
7. Make sure the port used for WebSocket (10081 in example above) is not blocked by your server/client's firewall. |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
79 |
|
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
80 |
8. Install [debugger version of Flash Player](http://www.adobe.com/support/flashplayer/downloads.html) to see Flash errors. |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
81 |
|
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
82 |
|
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
83 |
## Supported environments |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
84 |
|
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
85 |
It should work on: |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
86 |
|
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
87 |
- Google Chrome 4 or later (just uses native implementation) |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
88 |
- Firefox 3.x, 4.x, Internet Explorer 8, 9 + Flash Player 10 or later |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
89 |
|
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
90 |
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. |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
91 |
|
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
92 |
|
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
93 |
## Limitations/differences compared to native WebSocket |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
94 |
|
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
95 |
- You need some more lines in your JavaScript code. See "How to use it in your application" section above for details. |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
96 |
- It requires Flash Player 10 or later unless the browser supports native WebSocket. |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
97 |
- Your server must provide Flash socket policy file, unless you use web-socket-ruby or em-websocket. See "Flash socket policy file" section below for details. |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
98 |
- It has limited support for Cookies on WebSocket. See "Cookie support" section below for details. |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
99 |
- It doesn't use proxies specified in browser config. See "Proxy support" section below for details. |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
100 |
|
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
101 |
|
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
102 |
### Flash socket policy file |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
103 |
|
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
104 |
This implementation uses Flash's socket, which means that your server must provide Flash socket policy file to declare the server accepts connections from Flash. |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
105 |
|
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
106 |
If you use [web-socket-ruby](http://github.com/gimite/web-socket-ruby/tree/master) or [em-websocket](https://github.com/igrigorik/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. |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
107 |
|
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
108 |
If you use other Web Socket server implementation, you need to provide socket policy file yourself. See [Setting up A Flash Socket Policy File](http://www.lightsphere.com/dev/articles/flash_socket_policy.html) for details and sample script to run socket policy file server. [node.js implementation is available here](https://github.com/3rd-Eden/FlashPolicyFileServer). |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
109 |
|
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
110 |
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. |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
111 |
|
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
112 |
|
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
113 |
### Cookie support |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
114 |
|
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
115 |
web-socket-js has limited supported for Cookies on WebSocket. |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
116 |
|
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
117 |
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. |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
118 |
|
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
119 |
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. |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
120 |
|
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
121 |
|
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
122 |
### Proxy support |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
123 |
|
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
124 |
[The WebSocket spec](http://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-10) specifies instructions for User Agents to support proxied connections by implementing the HTTP CONNECT method. |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
125 |
|
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
126 |
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. |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
127 |
|
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
128 |
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. |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
129 |
|
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
130 |
|
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
131 |
## How to host HTML file and SWF file in different domains |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
132 |
|
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
133 |
By default, HTML file and SWF file must be in the same domain. You can follow steps below to allow hosting them in different domain. |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
134 |
|
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
135 |
**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. |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
136 |
|
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
137 |
1. Unzip WebSocketMainInsecure.zip to extract WebSocketMainInsecure.swf. |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
138 |
2. Put WebSocketMainInsecure.swf on your server, instead of WebSocketMain.swf. |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
139 |
3. In JavaScript, set WEB_SOCKET_SWF_LOCATION to URL of your WebSocketMainInsecure.swf. |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
140 |
|
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
141 |
|
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
142 |
## How to build WebSocketMain.swf |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
143 |
|
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
144 |
Install [Flex 4 SDK](http://opensource.adobe.com/wiki/display/flexsdk/Download+Flex+4). |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
145 |
|
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
146 |
$ cd flash-src |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
147 |
$ ./build.sh |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
148 |
|
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
149 |
|
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
150 |
## WebSocket protocol versions |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
151 |
|
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
152 |
- web-socket-js supports [hybi-10 version](http://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-10) of WebSocket protocol. |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
153 |
- web-socket-js doesn't speak other versions including hixie-76, which was supported by old version of this library. If you really need web-socket-js which speaks hixie-76, you can get it from [hixie-76 branch](https://github.com/gimite/web-socket-js/tree/hixie-76), but the branch is no longer maintained. |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
154 |
|
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
155 |
|
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
156 |
## License |
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
157 |
|
|
436a31d11f1d
Ajout du streaming des tweets par WebSocket
Raphael Velt <raph.velt@gmail.com>
parents:
diff
changeset
|
158 |
New BSD License. |