ws is a simple to use websocket implementation, up-to-date against RFC-6455, and probably the fastest WebSocket library for node.js.
Passes the quite extensive Autobahn test suite. See http://einaros.github.com/ws for the full reports.
Comes with a command line utility,
wscat, which can either act as a server (--listen), or client (--connect); Use it to debug simple websocket services.
disableHixieoption to true.)
protocolVersion: 8, or argument
-p 8for wscat)
protocolVersion: 13, or argument
-p 13for wscat)
See the echo.websocket.org example below for how to use the
npm install ws
var WebSocket = ;var ws = 'ws://www.host.com/path';ws;ws;
var WebSocket = ;var ws = 'ws://www.host.com/path';ws;
mask, as done for the send options above, will cause the data to be masked according to the websocket protocol. The same option applies for text data.
var WebSocketServer = Serverwss = port: 8080;wss;
// If the WebSocket is closed before the following send is attemptedws;// Errors (both immediate and async write errors) can be detected in an optional callback.// The callback is also the only way of being notified that data has actually been sent.ws;// Immediate errors can also be handled with try/catch-blocks, but **note**// that since sends are inherently asynchronous, socket write failures will *not*// be captured when this technique is used.tryws;catch e// handle error
var WebSocket = ;var ws = 'ws://echo.websocket.org/' protocolVersion: 8 origin: '';ws;ws;ws;
$ npm install -g ws $ wscat -c ws://echo.websocket.org -p 8 connected (press CTRL+C to quit) > hi there < hi there > are you a happy parrot? < are you a happy parrot?
For a full example with a browser client communicating with a ws server, see the examples folder.
Note that the usage together with Express 3.0 is quite different from Express 2.x. The difference is expressed in the two different serverstats-examples.
Otherwise, see the test cases.
See the doc/ directory for Node.js-like docs for the ws classes.
(The MIT License)
Copyright (c) 2011 Einar Otto Stangvik <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.