Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 247 lines (155 sloc) 6.204 kb
aed0fc8 Guillermo Rauch Loading bar fix for iPhone
rauchg authored
1 socket.io
2 =========
3
4 #### Sockets for the rest of us
507dc04 Guillermo Rauch Initial commit
rauchg authored
5
6fe5043 Guillermo Rauch Updated README
rauchg authored
6 The `socket.io` client is basically a simple HTTP Socket interface implementation.
7 It looks similar to WebSocket while providing additional features and
8 leveraging other transports when WebSocket is not supported by the user's
9 browser.
8180d30 Guillermo Rauch README fixes
rauchg authored
10
e2a5ff8 Arnout Kazemier fancy pancy redcarpet highlight
3rd-Eden authored
11 ```js
12 var socket = io.connect('http://domain.com');
13 socket.on('connect', function () {
14 // socket connected
15 });
16 socket.on('custom event', function () {
17 // server emitted a custom event
18 });
19 socket.on('disconnect', function () {
20 // socket disconnected
21 });
22 socket.send('hi there');
23 ```
8180d30 Guillermo Rauch README fixes
rauchg authored
24
6fe5043 Guillermo Rauch Updated README
rauchg authored
25 ### Recipes
8180d30 Guillermo Rauch README fixes
rauchg authored
26
6fe5043 Guillermo Rauch Updated README
rauchg authored
27 #### Utilizing namespaces (ie: multiple sockets)
8180d30 Guillermo Rauch README fixes
rauchg authored
28
6fe5043 Guillermo Rauch Updated README
rauchg authored
29 If you want to namespace all the messages and events emitted to a particular
30 endpoint, simply specify it as part of the `connect` uri:
8a34dc7 Guillermo Rauch Note about submodules
rauchg authored
31
e2a5ff8 Arnout Kazemier fancy pancy redcarpet highlight
3rd-Eden authored
32 ```js
33 var chat = io.connect('http://localhost/chat');
34 chat.on('connect', function () {
35 // chat socket connected
36 });
33a89f8 Guillermo Rauch Clarification for serving Flash
rauchg authored
37
e2a5ff8 Arnout Kazemier fancy pancy redcarpet highlight
3rd-Eden authored
38 var news = io.connect('/news'); // io.connect auto-detects host
33539df Chad Whitacre Fix minor type in README.md.
whit537 authored
39 news.on('connect', function () {
e2a5ff8 Arnout Kazemier fancy pancy redcarpet highlight
3rd-Eden authored
40 // news socket connected
41 });
42 ```
33a89f8 Guillermo Rauch Clarification for serving Flash
rauchg authored
43
6fe5043 Guillermo Rauch Updated README
rauchg authored
44 #### Emitting custom events
7546cee Arnout Kazemier Added a note about cross domain .swf files
3rd-Eden authored
45
6fe5043 Guillermo Rauch Updated README
rauchg authored
46 To ease with the creation of applications, you can emit custom events outside
47 of the global `message` event.
8180d30 Guillermo Rauch README fixes
rauchg authored
48
e2a5ff8 Arnout Kazemier fancy pancy redcarpet highlight
3rd-Eden authored
49 ```js
50 var socket = io.connect();
51 socket.emit('server custom event', { my: 'data' });
52 ```
507dc04 Guillermo Rauch Initial commit
rauchg authored
53
6fe5043 Guillermo Rauch Updated README
rauchg authored
54 #### Forcing disconnection
507dc04 Guillermo Rauch Initial commit
rauchg authored
55
e2a5ff8 Arnout Kazemier fancy pancy redcarpet highlight
3rd-Eden authored
56 ```js
57 var socket = io.connect();
58 socket.on('connect', function () {
59 socket.disconnect();
60 });
61 ```
d860b4f Arnout Kazemier Updated the documentation with some of the missing options and propperti...
3rd-Eden authored
62
6fe5043 Guillermo Rauch Updated README
rauchg authored
63 ### Documentation
d860b4f Arnout Kazemier Updated the documentation with some of the missing options and propperti...
3rd-Eden authored
64
6fe5043 Guillermo Rauch Updated README
rauchg authored
65 #### io#connect
507dc04 Guillermo Rauch Initial commit
rauchg authored
66
e2a5ff8 Arnout Kazemier fancy pancy redcarpet highlight
3rd-Eden authored
67 ```js
68 io.connect(uri, [options]);
69 ```
507dc04 Guillermo Rauch Initial commit
rauchg authored
70
6fe5043 Guillermo Rauch Updated README
rauchg authored
71 ##### Options:
507dc04 Guillermo Rauch Initial commit
rauchg authored
72
73 - *resource*
74
e2a5ff8 Arnout Kazemier fancy pancy redcarpet highlight
3rd-Eden authored
75 socket.io
507dc04 Guillermo Rauch Initial commit
rauchg authored
76
77 The resource is what allows the `socket.io` server to identify incoming connections by `socket.io` clients. In other words, any HTTP server can implement socket.io and still serve other normal, non-realtime HTTP requests.
78
79 - *transports*
80
e2a5ff8 Arnout Kazemier fancy pancy redcarpet highlight
3rd-Eden authored
81 ```js
82 ['websocket', 'flashsocket', 'htmlfile', 'xhr-multipart', 'xhr-polling', 'jsonp-polling']
83 ```
507dc04 Guillermo Rauch Initial commit
rauchg authored
84
e2a5ff8 Arnout Kazemier fancy pancy redcarpet highlight
3rd-Eden authored
85 A list of the transports to attempt to utilize (in order of preference).
d860b4f Arnout Kazemier Updated the documentation with some of the missing options and propperti...
3rd-Eden authored
86
6fe5043 Guillermo Rauch Updated README
rauchg authored
87 - *'connect timeout'*
d860b4f Arnout Kazemier Updated the documentation with some of the missing options and propperti...
3rd-Eden authored
88
e2a5ff8 Arnout Kazemier fancy pancy redcarpet highlight
3rd-Eden authored
89 ```js
90 5000
91 ```
92
93 The amount of milliseconds a transport has to create a connection before we consider it timed out.
94
6fe5043 Guillermo Rauch Updated README
rauchg authored
95 - *'try multiple transports'*
d860b4f Arnout Kazemier Updated the documentation with some of the missing options and propperti...
3rd-Eden authored
96
e2a5ff8 Arnout Kazemier fancy pancy redcarpet highlight
3rd-Eden authored
97 ```js
98 true
99 ```
d860b4f Arnout Kazemier Updated the documentation with some of the missing options and propperti...
3rd-Eden authored
100
e2a5ff8 Arnout Kazemier fancy pancy redcarpet highlight
3rd-Eden authored
101 A boolean indicating if we should try other transports when the connectTimeout occurs.
102
cd0b83a Arnout Kazemier Inital draft of reconnection support.
3rd-Eden authored
103 - *reconnect*
104
e2a5ff8 Arnout Kazemier fancy pancy redcarpet highlight
3rd-Eden authored
105 ```js
106 true
107 ```
cd0b83a Arnout Kazemier Inital draft of reconnection support.
3rd-Eden authored
108
e2a5ff8 Arnout Kazemier fancy pancy redcarpet highlight
3rd-Eden authored
109 A boolean indicating if we should automatically reconnect if a connection is disconnected.
cd0b83a Arnout Kazemier Inital draft of reconnection support.
3rd-Eden authored
110
6fe5043 Guillermo Rauch Updated README
rauchg authored
111 - *'reconnection delay'*
cd0b83a Arnout Kazemier Inital draft of reconnection support.
3rd-Eden authored
112
e2a5ff8 Arnout Kazemier fancy pancy redcarpet highlight
3rd-Eden authored
113 ```js
114 500
115 ```
cd0b83a Arnout Kazemier Inital draft of reconnection support.
3rd-Eden authored
116
e2a5ff8 Arnout Kazemier fancy pancy redcarpet highlight
3rd-Eden authored
117 The amount of milliseconds before we try to connect to the server again. We are using a exponential back off algorithm for the following reconnections, on each reconnect attempt this value will get multiplied (500 > 1000 > 2000 > 4000 > 8000).
cd0b83a Arnout Kazemier Inital draft of reconnection support.
3rd-Eden authored
118
119
6fe5043 Guillermo Rauch Updated README
rauchg authored
120 - *'max reconnection attempts'*
cd0b83a Arnout Kazemier Inital draft of reconnection support.
3rd-Eden authored
121
e2a5ff8 Arnout Kazemier fancy pancy redcarpet highlight
3rd-Eden authored
122 ```js
123 10
124 ```
cd0b83a Arnout Kazemier Inital draft of reconnection support.
3rd-Eden authored
125
e2a5ff8 Arnout Kazemier fancy pancy redcarpet highlight
3rd-Eden authored
126 The amount of attempts should we make using the current transport to connect to the server? After this we will do one final attempt, and re-try with all enabled transport methods before we give up.
507dc04 Guillermo Rauch Initial commit
rauchg authored
127
d860b4f Arnout Kazemier Updated the documentation with some of the missing options and propperti...
3rd-Eden authored
128 ##### Properties:
507dc04 Guillermo Rauch Initial commit
rauchg authored
129
130 - *options*
131
e2a5ff8 Arnout Kazemier fancy pancy redcarpet highlight
3rd-Eden authored
132 The passed in options combined with the defaults.
507dc04 Guillermo Rauch Initial commit
rauchg authored
133
134 - *connected*
135
e2a5ff8 Arnout Kazemier fancy pancy redcarpet highlight
3rd-Eden authored
136 Whether the socket is connected or not.
137
507dc04 Guillermo Rauch Initial commit
rauchg authored
138 - *connecting*
139
e2a5ff8 Arnout Kazemier fancy pancy redcarpet highlight
3rd-Eden authored
140 Whether the socket is connecting or not.
01cbb21 Arnout Kazemier Updated the readme with a new event.
3rd-Eden authored
141
142 - *reconnecting*
143
e2a5ff8 Arnout Kazemier fancy pancy redcarpet highlight
3rd-Eden authored
144 Whether we are reconnecting or not.
145
146 - *transport*
507dc04 Guillermo Rauch Initial commit
rauchg authored
147
e2a5ff8 Arnout Kazemier fancy pancy redcarpet highlight
3rd-Eden authored
148 The transport instance.
507dc04 Guillermo Rauch Initial commit
rauchg authored
149
d860b4f Arnout Kazemier Updated the documentation with some of the missing options and propperti...
3rd-Eden authored
150 ##### Methods:
e2a5ff8 Arnout Kazemier fancy pancy redcarpet highlight
3rd-Eden authored
151
adde746 Arnout Kazemier Updated the README to reflect the API updates. Added .once support and s...
3rd-Eden authored
152 - *connect(λ)*
507dc04 Guillermo Rauch Initial commit
rauchg authored
153
e2a5ff8 Arnout Kazemier fancy pancy redcarpet highlight
3rd-Eden authored
154 Establishes a connection. If λ is supplied as argument, it will be called once the connection is established.
155
507dc04 Guillermo Rauch Initial commit
rauchg authored
156 - *send(message)*
e2a5ff8 Arnout Kazemier fancy pancy redcarpet highlight
3rd-Eden authored
157
158 A string of data to send.
159
507dc04 Guillermo Rauch Initial commit
rauchg authored
160 - *disconnect*
161
e2a5ff8 Arnout Kazemier fancy pancy redcarpet highlight
3rd-Eden authored
162 Closes the connection.
163
587c579 Guillermo Rauch Implementation of buffering for XHR send messages
rauchg authored
164 - *on(event, λ)*
507dc04 Guillermo Rauch Initial commit
rauchg authored
165
e2a5ff8 Arnout Kazemier fancy pancy redcarpet highlight
3rd-Eden authored
166 Adds a listener for the event *event*.
adde746 Arnout Kazemier Updated the README to reflect the API updates. Added .once support and s...
3rd-Eden authored
167
168 - *once(event, λ)*
169
e2a5ff8 Arnout Kazemier fancy pancy redcarpet highlight
3rd-Eden authored
170 Adds a one time listener for the event *event*. The listener is removed after the first time the event is fired.
171
4f41c8f Utyasheva Oksana fixed README.
uoksana authored
172 - *removeListener(event, λ)*
507dc04 Guillermo Rauch Initial commit
rauchg authored
173
e2a5ff8 Arnout Kazemier fancy pancy redcarpet highlight
3rd-Eden authored
174 Removes the listener λ for the event *event*.
175
d860b4f Arnout Kazemier Updated the documentation with some of the missing options and propperti...
3rd-Eden authored
176 ##### Events:
507dc04 Guillermo Rauch Initial commit
rauchg authored
177
178 - *connect*
179
e2a5ff8 Arnout Kazemier fancy pancy redcarpet highlight
3rd-Eden authored
180 Fired when the connection is established and the handshake successful.
181
686e1d1 Daniel Beardsley Fixed the broken tryTransportsOnConnectTimeout option
danielbeardsley authored
182 - *connecting(transport_type)*
183
01cbb21 Arnout Kazemier Updated the readme with a new event.
3rd-Eden authored
184 Fired when a connection is attempted, passing the transport name.
e2a5ff8 Arnout Kazemier fancy pancy redcarpet highlight
3rd-Eden authored
185
686e1d1 Daniel Beardsley Fixed the broken tryTransportsOnConnectTimeout option
danielbeardsley authored
186 - *connect_failed*
187
01cbb21 Arnout Kazemier Updated the readme with a new event.
3rd-Eden authored
188 Fired when the connection timeout occurs after the last connection attempt.
e2a5ff8 Arnout Kazemier fancy pancy redcarpet highlight
3rd-Eden authored
189 This only fires if the `connectTimeout` option is set.
190 If the `tryTransportsOnConnectTimeout` option is set, this only fires once all
191 possible transports have been tried.
192
507dc04 Guillermo Rauch Initial commit
rauchg authored
193 - *message(message)*
e2a5ff8 Arnout Kazemier fancy pancy redcarpet highlight
3rd-Eden authored
194
195 Fired when a message arrives from the server
507dc04 Guillermo Rauch Initial commit
rauchg authored
196
197 - *close*
198
e2a5ff8 Arnout Kazemier fancy pancy redcarpet highlight
3rd-Eden authored
199 Fired when the connection is closed. Be careful with using this event, as some transports will fire it even under temporary, expected disconnections (such as XHR-Polling).
200
507dc04 Guillermo Rauch Initial commit
rauchg authored
201 - *disconnect*
202
e2a5ff8 Arnout Kazemier fancy pancy redcarpet highlight
3rd-Eden authored
203 Fired when the connection is considered disconnected.
204
63ce005 Arnout Kazemier Updated the documentation in the README
3rd-Eden authored
205 - *reconnect(transport_type,reconnectionAttempts)*
cd0b83a Arnout Kazemier Inital draft of reconnection support.
3rd-Eden authored
206
e2a5ff8 Arnout Kazemier fancy pancy redcarpet highlight
3rd-Eden authored
207 Fired when the connection has been re-established. This only fires if the `reconnect` option is set.
cd0b83a Arnout Kazemier Inital draft of reconnection support.
3rd-Eden authored
208
63ce005 Arnout Kazemier Updated the documentation in the README
3rd-Eden authored
209 - *reconnecting(reconnectionDelay,reconnectionAttempts)*
01cbb21 Arnout Kazemier Updated the readme with a new event.
3rd-Eden authored
210
e2a5ff8 Arnout Kazemier fancy pancy redcarpet highlight
3rd-Eden authored
211 Fired when a reconnection is attempted, passing the next delay for the next reconnection.
01cbb21 Arnout Kazemier Updated the readme with a new event.
3rd-Eden authored
212
cd0b83a Arnout Kazemier Inital draft of reconnection support.
3rd-Eden authored
213 - *reconnect_failed*
214
e2a5ff8 Arnout Kazemier fancy pancy redcarpet highlight
3rd-Eden authored
215 Fired when all reconnection attempts have failed and we where unsuccessful in reconnecting to the server.
aed0fc8 Guillermo Rauch Loading bar fix for iPhone
rauchg authored
216
146cfc3 Guillermo Rauch Added Arnout to contributors
rauchg authored
217 ### Contributors
8180d30 Guillermo Rauch README fixes
rauchg authored
218
1b19122 Guillermo Rauch Updated README
rauchg authored
219 Guillermo Rauch <guillermo@learnboost.com>
8180d30 Guillermo Rauch README fixes
rauchg authored
220
146cfc3 Guillermo Rauch Added Arnout to contributors
rauchg authored
221 Arnout Kazemier <info@3rd-eden.com>
222
aed0fc8 Guillermo Rauch Loading bar fix for iPhone
rauchg authored
223 ### License
8180d30 Guillermo Rauch README fixes
rauchg authored
224
225 (The MIT License)
226
1b19122 Guillermo Rauch Updated README
rauchg authored
227 Copyright (c) 2010 LearnBoost <dev@learnboost.com>
8180d30 Guillermo Rauch README fixes
rauchg authored
228
229 Permission is hereby granted, free of charge, to any person obtaining
230 a copy of this software and associated documentation files (the
231 'Software'), to deal in the Software without restriction, including
232 without limitation the rights to use, copy, modify, merge, publish,
233 distribute, sublicense, and/or sell copies of the Software, and to
234 permit persons to whom the Software is furnished to do so, subject to
235 the following conditions:
236
237 The above copyright notice and this permission notice shall be
238 included in all copies or substantial portions of the Software.
507dc04 Guillermo Rauch Initial commit
rauchg authored
239
8180d30 Guillermo Rauch README fixes
rauchg authored
240 THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
241 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
242 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
243 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
244 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
245 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
9804716 Guillermo Rauch Updated README
rauchg authored
246 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Something went wrong with that request. Please try again.