Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
146 lines (77 sloc) 2.5 KB

Class wsio

This class is exposed by require('').


  • {String}

Protocol revision number


  • {Object}
    • drafts {Function}
    • hybi {Function}

Client constructors for drafts 75/76/00, protocols 7/8/13.

wsio.listen(port, [fn], [options])

  • port {Number}
  • fn {Function}
  • options {Object}

Creates an http.Server which listens on the given port and attaches WS to it. It returns 501 Not Implemented for regular http requests.

fn is the callback for listen. The options object can be supplied as second parameter as well. See wsio.Server constructor API for options.

wsio.attach(server, [options])

  • server {http.Server}
  • options {Object}

Captures upgrade requests for a http.Server. In other words, makes a regular http.Server websocket-compatible. See wsio.Server constructor API for options.

Class wsio.Server

Is an EventEmitter

new wsio.Server([options])

  • options {Object}
    • path {String}
    • clientTracking {Boolean}

Initializes the server. If path is set, the server listens only on this path. By default, it listens for upgrade events on any path. clientTracking enables client tracking (Server.clients). Defaults is true.

server.handleUpgrade(req, socket, head)

  • req {http.ServerRequest}
  • socket {net.Socket}
  • head {Buffer}

Handles an incoming request that triggered an upgrade event.


  • {Object}

Array of all connected clients


  • {Number}

The number of connected clients

Event 'connection'

function (socket) { }

Fired when a new connection is established.

socket is an instance of wsio.Socket.

Class wsio.Socket

Is an EventEmitter


  • {http.ServerRequest}

Request that originated the connection


  • {net.Socket}

Stream that originated the connection


  • {String}

Can be opening, open, closed.

  • {String}

Protocol name: websocket-hixie, websocket


  • {String}

Protocol version: hixie-75, hixie-76, hybi


  • data {String}

Writes data to the socket.



Closes the socket.


Forcibly closes the socket.

Event 'message'

function (data) { }

  • data {String}

Fired when data is received

Event 'error'

function (error) { }

Event 'close'

function () { }

Fired when the connection is closed.

Jump to Line
Something went wrong with that request. Please try again.