\href{\#backers}{\texttt{ }} \href{\#sponsors}{\texttt{ }} \href{https://travis-ci.org/socketio/socket.io}{\texttt{ }} \href{https://david-dm.org/socketio/socket.io}{\texttt{ }} \href{https://david-dm.org/socketio/socket.io\#info=devDependencies}{\texttt{ }} \href{https://www.npmjs.com/package/socket.io}{\texttt{ }}  \href{https://slackin-socketio.now.sh}{\texttt{ }}\hypertarget{md_sfcode_node_modules_socket_io_Readme_autotoc_md27588}{}\doxysection{Features}\label{md_sfcode_node_modules_socket_io_Readme_autotoc_md27588}
Socket.\+IO enables real-\/time bidirectional event-\/based communication. It consists of\+:


\begin{DoxyItemize}
\item a Node.\+js server (this repository)
\item a \href{https://github.com/socketio/socket.io-client}{\texttt{ Javascript client library}} for the browser (or a Node.\+js client)
\end{DoxyItemize}

Some implementations in other languages are also available\+:


\begin{DoxyItemize}
\item \href{https://github.com/socketio/socket.io-client-java}{\texttt{ Java}}
\item \href{https://github.com/socketio/socket.io-client-cpp}{\texttt{ C++}}
\item \href{https://github.com/socketio/socket.io-client-swift}{\texttt{ Swift}}
\item \href{https://github.com/rikulo/socket.io-client-dart}{\texttt{ Dart}}
\end{DoxyItemize}

Its main features are\+:\hypertarget{md_sfcode_node_modules_socket_io_Readme_autotoc_md27589}{}\doxysubsubsection{Reliability}\label{md_sfcode_node_modules_socket_io_Readme_autotoc_md27589}
Connections are established even in the presence of\+:
\begin{DoxyItemize}
\item proxies and load balancers.
\item personal firewall and antivirus software.
\end{DoxyItemize}

For this purpose, it relies on \href{https://github.com/socketio/engine.io}{\texttt{ Engine.\+IO}}, which first establishes a long-\/polling connection, then tries to upgrade to better transports that are \char`\"{}tested\char`\"{} on the side, like Web\+Socket. Please see the \href{https://github.com/socketio/engine.io\#goals}{\texttt{ Goals}} section for more information.\hypertarget{md_sfcode_node_modules_socket_io_Readme_autotoc_md27590}{}\doxysubsubsection{Auto-\/reconnection support}\label{md_sfcode_node_modules_socket_io_Readme_autotoc_md27590}
Unless instructed otherwise a disconnected client will try to reconnect forever, until the server is available again. Please see the available reconnection options \href{https://github.com/socketio/socket.io-client/blob/master/docs/API.md\#new-managerurl-options}{\texttt{ here}}.\hypertarget{md_sfcode_node_modules_socket_io_Readme_autotoc_md27591}{}\doxysubsubsection{Disconnection detection}\label{md_sfcode_node_modules_socket_io_Readme_autotoc_md27591}
A heartbeat mechanism is implemented at the Engine.\+IO level, allowing both the server and the client to know when the other one is not responding anymore.

That functionality is achieved with timers set on both the server and the client, with timeout values (the {\ttfamily ping\+Interval} and {\ttfamily ping\+Timeout} parameters) shared during the connection handshake. Those timers require any subsequent client calls to be directed to the same server, hence the {\ttfamily sticky-\/session} requirement when using multiples nodes.\hypertarget{md_sfcode_node_modules_socket_io_Readme_autotoc_md27592}{}\doxysubsubsection{Binary support}\label{md_sfcode_node_modules_socket_io_Readme_autotoc_md27592}
Any serializable data structures can be emitted, including\+:


\begin{DoxyItemize}
\item \href{https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer}{\texttt{ Array\+Buffer}} and \href{https://developer.mozilla.org/en-US/docs/Web/API/Blob}{\texttt{ Blob}} in the browser
\item \href{https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer}{\texttt{ Array\+Buffer}} and \href{https://nodejs.org/api/buffer.html}{\texttt{ Buffer}} in Node.\+js
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_socket_io_Readme_autotoc_md27593}{}\doxysubsubsection{Simple and convenient API}\label{md_sfcode_node_modules_socket_io_Readme_autotoc_md27593}
Sample code\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{io.on('connection', socket => \{}
\DoxyCodeLine{  socket.emit('request', /* … */); // emit an event to the socket}
\DoxyCodeLine{  io.emit('broadcast', /* … */); // emit an event to all connected sockets}
\DoxyCodeLine{  socket.on('reply', () => \{ /* … */ \}); // listen to the event}
\DoxyCodeLine{\}); }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_socket_io_Readme_autotoc_md27594}{}\doxysubsubsection{Cross-\/browser}\label{md_sfcode_node_modules_socket_io_Readme_autotoc_md27594}
Browser support is tested in Saucelabs\+:

\href{https://saucelabs.com/u/socket}{\texttt{ }}\hypertarget{md_sfcode_node_modules_socket_io_Readme_autotoc_md27595}{}\doxysubsubsection{Multiplexing support}\label{md_sfcode_node_modules_socket_io_Readme_autotoc_md27595}
In order to create separation of concerns within your application (for example per module, or based on permissions), Socket.\+IO allows you to create several {\ttfamily Namespaces}, which will act as separate communication channels but will share the same underlying connection.\hypertarget{md_sfcode_node_modules_socket_io_Readme_autotoc_md27596}{}\doxysubsubsection{Room support}\label{md_sfcode_node_modules_socket_io_Readme_autotoc_md27596}
Within each {\ttfamily Namespace}, you can define arbitrary channels, called {\ttfamily Rooms}, that sockets can join and leave. You can then broadcast to any given room, reaching every socket that has joined it.

This is a useful feature to send notifications to a group of users, or to a given user connected on several devices for example.

{\bfseries{Note\+:}} Socket.\+IO is not a Web\+Socket implementation. Although Socket.\+IO indeed uses Web\+Socket as a transport when possible, it adds some metadata to each packet\+: the packet type, the namespace and the ack id when a message acknowledgement is needed. That is why a Web\+Socket client will not be able to successfully connect to a Socket.\+IO server, and a Socket.\+IO client will not be able to connect to a Web\+Socket server (like {\ttfamily ws\+://echo.websocket.\+org}) either. Please see the protocol specification \href{https://github.com/socketio/socket.io-protocol}{\texttt{ here}}.\hypertarget{md_sfcode_node_modules_socket_io_Readme_autotoc_md27597}{}\doxysection{Installation}\label{md_sfcode_node_modules_socket_io_Readme_autotoc_md27597}

\begin{DoxyCode}{0}
\DoxyCodeLine{npm install socket.io }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_socket_io_Readme_autotoc_md27598}{}\doxysection{How to use}\label{md_sfcode_node_modules_socket_io_Readme_autotoc_md27598}
The following example attaches socket.\+io to a plain Node.\+JS HTTP server listening on port {\ttfamily 3000}.


\begin{DoxyCode}{0}
\DoxyCodeLine{const server = require('http').createServer();}
\DoxyCodeLine{const io = require('socket.io')(server);}
\DoxyCodeLine{io.on('connection', client => \{}
\DoxyCodeLine{  client.on('event', data => \{ /* … */ \});}
\DoxyCodeLine{  client.on('disconnect', () => \{ /* … */ \});}
\DoxyCodeLine{\});}
\DoxyCodeLine{server.listen(3000); }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_socket_io_Readme_autotoc_md27599}{}\doxysubsection{Standalone}\label{md_sfcode_node_modules_socket_io_Readme_autotoc_md27599}

\begin{DoxyCode}{0}
\DoxyCodeLine{const io = require('socket.io')();}
\DoxyCodeLine{io.on('connection', client => \{ ... \});}
\DoxyCodeLine{io.listen(3000); }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_socket_io_Readme_autotoc_md27600}{}\doxysubsection{In conjunction with Express}\label{md_sfcode_node_modules_socket_io_Readme_autotoc_md27600}
Starting with {\bfseries{3.\+0}}, express applications have become request handler functions that you pass to {\ttfamily http} or {\ttfamily http} {\ttfamily Server} instances. You need to pass the {\ttfamily Server} to {\ttfamily socket.\+io}, and not the express application function. Also make sure to call {\ttfamily .listen} on the {\ttfamily server}, not the {\ttfamily app}.


\begin{DoxyCode}{0}
\DoxyCodeLine{const app = require('express')();}
\DoxyCodeLine{const server = require('http').createServer(app);}
\DoxyCodeLine{const io = require('socket.io')(server);}
\DoxyCodeLine{io.on('connection', () => \{ /* … */ \});}
\DoxyCodeLine{server.listen(3000); }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_socket_io_Readme_autotoc_md27601}{}\doxysubsection{In conjunction with Koa}\label{md_sfcode_node_modules_socket_io_Readme_autotoc_md27601}
Like Express.\+JS, Koa works by exposing an application as a request handler function, but only by calling the {\ttfamily callback} method.


\begin{DoxyCode}{0}
\DoxyCodeLine{const app = require('koa')();}
\DoxyCodeLine{const server = require('http').createServer(app.callback());}
\DoxyCodeLine{const io = require('socket.io')(server);}
\DoxyCodeLine{io.on('connection', () => \{ /* … */ \});}
\DoxyCodeLine{server.listen(3000); }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_socket_io_Readme_autotoc_md27602}{}\doxysection{Documentation}\label{md_sfcode_node_modules_socket_io_Readme_autotoc_md27602}
Please see the documentation here. Contributions are welcome!\hypertarget{md_sfcode_node_modules_socket_io_Readme_autotoc_md27603}{}\doxysection{Debug / logging}\label{md_sfcode_node_modules_socket_io_Readme_autotoc_md27603}
Socket.\+IO is powered by \href{https://github.com/visionmedia/debug}{\texttt{ debug}}. In order to see all the debug output, run your app with the environment variable {\ttfamily DEBUG} including the desired scope.

To see the output from all of Socket.\+IO\textquotesingle{}s debugging scopes you can use\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{DEBUG=socket.io* node myapp }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_socket_io_Readme_autotoc_md27604}{}\doxysection{Testing}\label{md_sfcode_node_modules_socket_io_Readme_autotoc_md27604}

\begin{DoxyCode}{0}
\DoxyCodeLine{npm test }

\end{DoxyCode}
 This runs the {\ttfamily gulp} task {\ttfamily test}. By default the test will be run with the source code in {\ttfamily lib} directory.

Set the environmental variable {\ttfamily TEST\+\_\+\+VERSION} to {\ttfamily compat} to test the transpiled es5-\/compat version of the code.

The {\ttfamily gulp} task {\ttfamily test} will always transpile the source code into es5 and export to {\ttfamily dist} first before running the test.\hypertarget{md_sfcode_node_modules_socket_io_Readme_autotoc_md27605}{}\doxysection{Backers}\label{md_sfcode_node_modules_socket_io_Readme_autotoc_md27605}
Support us with a monthly donation and help us continue our activities. \mbox{[}\href{https://opencollective.com/socketio\#backer}{\texttt{ Become a backer}}\mbox{]}

\href{https://opencollective.com/socketio/backer/0/website}{\texttt{ }} \href{https://opencollective.com/socketio/backer/1/website}{\texttt{ }} \href{https://opencollective.com/socketio/backer/2/website}{\texttt{ }} \href{https://opencollective.com/socketio/backer/3/website}{\texttt{ }} \href{https://opencollective.com/socketio/backer/4/website}{\texttt{ }} \href{https://opencollective.com/socketio/backer/5/website}{\texttt{ }} \href{https://opencollective.com/socketio/backer/6/website}{\texttt{ }} \href{https://opencollective.com/socketio/backer/7/website}{\texttt{ }} \href{https://opencollective.com/socketio/backer/8/website}{\texttt{ }} \href{https://opencollective.com/socketio/backer/9/website}{\texttt{ }} \href{https://opencollective.com/socketio/backer/10/website}{\texttt{ }} \href{https://opencollective.com/socketio/backer/11/website}{\texttt{ }} \href{https://opencollective.com/socketio/backer/12/website}{\texttt{ }} \href{https://opencollective.com/socketio/backer/13/website}{\texttt{ }} \href{https://opencollective.com/socketio/backer/14/website}{\texttt{ }} \href{https://opencollective.com/socketio/backer/15/website}{\texttt{ }} \href{https://opencollective.com/socketio/backer/16/website}{\texttt{ }} \href{https://opencollective.com/socketio/backer/17/website}{\texttt{ }} \href{https://opencollective.com/socketio/backer/18/website}{\texttt{ }} \href{https://opencollective.com/socketio/backer/19/website}{\texttt{ }} \href{https://opencollective.com/socketio/backer/20/website}{\texttt{ }} \href{https://opencollective.com/socketio/backer/21/website}{\texttt{ }} \href{https://opencollective.com/socketio/backer/22/website}{\texttt{ }} \href{https://opencollective.com/socketio/backer/23/website}{\texttt{ }} \href{https://opencollective.com/socketio/backer/24/website}{\texttt{ }} \href{https://opencollective.com/socketio/backer/25/website}{\texttt{ }} \href{https://opencollective.com/socketio/backer/26/website}{\texttt{ }} \href{https://opencollective.com/socketio/backer/27/website}{\texttt{ }} \href{https://opencollective.com/socketio/backer/28/website}{\texttt{ }} \href{https://opencollective.com/socketio/backer/29/website}{\texttt{ }}\hypertarget{md_sfcode_node_modules_socket_io_Readme_autotoc_md27606}{}\doxysection{Sponsors}\label{md_sfcode_node_modules_socket_io_Readme_autotoc_md27606}
Become a sponsor and get your logo on our README on Github with a link to your site. \mbox{[}\href{https://opencollective.com/socketio\#sponsor}{\texttt{ Become a sponsor}}\mbox{]}

\href{https://opencollective.com/socketio/sponsor/0/website}{\texttt{ }} \href{https://opencollective.com/socketio/sponsor/1/website}{\texttt{ }} \href{https://opencollective.com/socketio/sponsor/2/website}{\texttt{ }} \href{https://opencollective.com/socketio/sponsor/3/website}{\texttt{ }} \href{https://opencollective.com/socketio/sponsor/4/website}{\texttt{ }} \href{https://opencollective.com/socketio/sponsor/5/website}{\texttt{ }} \href{https://opencollective.com/socketio/sponsor/6/website}{\texttt{ }} \href{https://opencollective.com/socketio/sponsor/7/website}{\texttt{ }} \href{https://opencollective.com/socketio/sponsor/8/website}{\texttt{ }} \href{https://opencollective.com/socketio/sponsor/9/website}{\texttt{ }} \href{https://opencollective.com/socketio/sponsor/10/website}{\texttt{ }} \href{https://opencollective.com/socketio/sponsor/11/website}{\texttt{ }} \href{https://opencollective.com/socketio/sponsor/12/website}{\texttt{ }} \href{https://opencollective.com/socketio/sponsor/13/website}{\texttt{ }} \href{https://opencollective.com/socketio/sponsor/14/website}{\texttt{ }} \href{https://opencollective.com/socketio/sponsor/15/website}{\texttt{ }} \href{https://opencollective.com/socketio/sponsor/16/website}{\texttt{ }} \href{https://opencollective.com/socketio/sponsor/17/website}{\texttt{ }} \href{https://opencollective.com/socketio/sponsor/18/website}{\texttt{ }} \href{https://opencollective.com/socketio/sponsor/19/website}{\texttt{ }} \href{https://opencollective.com/socketio/sponsor/20/website}{\texttt{ }} \href{https://opencollective.com/socketio/sponsor/21/website}{\texttt{ }} \href{https://opencollective.com/socketio/sponsor/22/website}{\texttt{ }} \href{https://opencollective.com/socketio/sponsor/23/website}{\texttt{ }} \href{https://opencollective.com/socketio/sponsor/24/website}{\texttt{ }} \href{https://opencollective.com/socketio/sponsor/25/website}{\texttt{ }} \href{https://opencollective.com/socketio/sponsor/26/website}{\texttt{ }} \href{https://opencollective.com/socketio/sponsor/27/website}{\texttt{ }} \href{https://opencollective.com/socketio/sponsor/28/website}{\texttt{ }} \href{https://opencollective.com/socketio/sponsor/29/website}{\texttt{ }}\hypertarget{md_sfcode_node_modules_socket_io_Readme_autotoc_md27607}{}\doxysection{License}\label{md_sfcode_node_modules_socket_io_Readme_autotoc_md27607}
\mbox{[}MIT\mbox{]}(LICENSE) 