Socket.IO client for the browser and node.js
socket.io client is basically a simple HTTP Socket interface implementation.
It looks similar to WebSocket while providing additional features and
leveraging other transports when WebSocket is not supported by the user's
var socket = ioconnect'';socketon'connect'// socket connected;socketon'custom event'// server emitted a custom event;socketon'disconnect'// socket disconnected;socketsend'hi there';
If you want to namespace all the messages and events emitted to a particular
endpoint, simply specify it as part of the
var chat = ioconnect'';chaton'connect'// chat socket connected;var news = ioconnect'/news'; // io.connect auto-detects hostnewson'connect'// news socket connected;
To ease with the creation of applications, you can emit custom events outside
of the global
var socket = ioconnect;socketemit'server custom event' my: 'data' ;
var socket = ioconnect;socketon'connect'socketdisconnect;;
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.
'websocket' 'flashsocket' 'htmlfile' 'xhr-multipart' 'xhr-polling' 'jsonp-polling'
A list of the transports to attempt to utilize (in order of preference).
The amount of milliseconds a transport has to create a connection before we consider it timed out.
A boolean indicating if we should try other transports when the connectTimeout occurs.
A boolean indicating if we should automatically reconnect if a connection is disconnected.
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).
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.
The passed in options combined with the defaults.
Whether the socket is connected or not.
Whether the socket is connecting or not.
Whether we are reconnecting or not.
The transport instance.
Establishes a connection. If λ is supplied as argument, it will be called once the connection is established.
A string of data to send.
Closes the connection.
Adds a listener for the event event.
Adds a one time listener for the event event. The listener is removed after the first time the event is fired.
Removes the listener λ for the event event.
Fired when the connection is established and the handshake successful.
Fired when a connection is attempted, passing the transport name.
Fired when the connection timeout occurs after the last connection attempt.
This only fires if the
connectTimeout option is set.
tryTransportsOnConnectTimeout option is set, this only fires once all
possible transports have been tried.
Fired when a message arrives from the server
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).
Fired when the connection is considered disconnected.
Fired when the connection has been re-established. This only fires if the
reconnect option is set.
Fired when a reconnection is attempted, passing the next delay for the next reconnection.
Fired when all reconnection attempts have failed and we where unsuccessful in reconnecting to the server.
Guillermo Rauch <firstname.lastname@example.org>
Arnout Kazemier <email@example.com>
(The MIT License)
Copyright (c) 2010 LearnBoost <firstname.lastname@example.org>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.