All Projects → hugmanrique → Turbo Ws

hugmanrique / Turbo Ws

Licence: mit
💨 Blazing fast low-level WebSocket server

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Turbo Ws

Autobahn Testsuite
Autobahn WebSocket protocol testsuite
Stars: ✭ 603 (-6.8%)
Mutual labels:  websocket, websocket-server
Ws
Simple to use, blazing fast and thoroughly tested WebSocket client and server for Node.js
Stars: ✭ 17,419 (+2592.27%)
Mutual labels:  websocket, websocket-server
Ws Tcp Relay
A simple relay between WebSocket clients and TCP servers
Stars: ✭ 186 (-71.25%)
Mutual labels:  websocket, websocket-server
Websocket
WSServer is a fast, configurable, and extendable WebSocket Server for UNIX systems written in C (C11).
Stars: ✭ 144 (-77.74%)
Mutual labels:  websocket, websocket-server
Websocket
simple php websocket server + demos + yii/yii2 integration + php 7 support
Stars: ✭ 363 (-43.89%)
Mutual labels:  websocket, websocket-server
Embedded Jetty Websocket Examples
Embedded Jetty WebSocket Examples
Stars: ✭ 159 (-75.43%)
Mutual labels:  websocket, websocket-server
Beast
HTTP and WebSocket built on Boost.Asio in C++11
Stars: ✭ 3,241 (+400.93%)
Mutual labels:  websocket, websocket-server
Sketchpad
Sketchpad is fully customisable collaborative whiteboard plugin written in pure JavaScript.
Stars: ✭ 85 (-86.86%)
Mutual labels:  websocket, websocket-server
Websockets
Library for building WebSocket servers and clients in Python
Stars: ✭ 3,724 (+475.58%)
Mutual labels:  websocket, websocket-server
Websocketlistener
A lightweight and scalable asynchronous WebSocket listener
Stars: ✭ 295 (-54.4%)
Mutual labels:  websocket, websocket-server
Php Wss
Web-socket server/client with multi-process and parse templates support on server and send/receive options on client
Stars: ✭ 117 (-81.92%)
Mutual labels:  websocket, websocket-server
Websocket
The Hoa\Websocket library.
Stars: ✭ 421 (-34.93%)
Mutual labels:  websocket, websocket-server
Sandstone
PHP microframework designed to build a RestApi working together with a websocket server. Build a real time RestApi!
Stars: ✭ 98 (-84.85%)
Mutual labels:  websocket, websocket-server
Libhv
🔥 比libevent、libuv更易用的国产网络库。A c/c++ network library for developing TCP/UDP/SSL/HTTP/WebSocket client/server.
Stars: ✭ 3,355 (+418.55%)
Mutual labels:  websocket, websocket-server
Arduinowebsockets
arduinoWebSockets
Stars: ✭ 1,265 (+95.52%)
Mutual labels:  websocket, websocket-server
Cwebsocket
cWebsocket is lightweight websocket server library
Stars: ✭ 241 (-62.75%)
Mutual labels:  websocket, websocket-server
Cebsocket
Lightweight WebSocket library for C.
Stars: ✭ 73 (-88.72%)
Mutual labels:  websocket, websocket-server
Deno Websocket
🦕 A simple WebSocket library like ws of node.js library for deno
Stars: ✭ 74 (-88.56%)
Mutual labels:  websocket, websocket-server
Microwebsrv2
The last Micro Web Server for IoTs (MicroPython) or large servers (CPython), that supports WebSockets, routes, template engine and with really optimized architecture (mem allocations, async I/Os). Ready for ESP32, STM32 on Pyboard, Pycom's chipsets (WiPy, LoPy, ...). Robust, efficient and documented!
Stars: ✭ 295 (-54.4%)
Mutual labels:  websocket, websocket-server
Microwebsrv
A micro HTTP Web server that supports WebSockets, html/python language templating and routing handlers, for MicroPython (used on Pycom modules & ESP32)
Stars: ✭ 420 (-35.09%)
Mutual labels:  websocket, websocket-server

💨 turbo-ws

npm node deps tests coverage license

A blazing fast low-level WebSocket server based on turbo-net and the awesome ws server library for Node.js

Features

  • Supports thousands of concurrent connections with minimal CPU and RAM impact.
  • Binary and text frames are supported. That means you can directly send Node's Buffers or Strings if you prefer.
  • Built with reliability in mind.

Getting Started

Install turbo-ws using npm:

npm install --save @hugmanrique/turbo-ws

Or via yarn:

yarn add @hugmanrique/turbo-ws

The minimum supported Node version is v8.10.0.

Let's get started by creating a WebSocket server:

import Server from '@hugmanrique/turbo-ws';

const server = new Server();
const port = 80;

Then, add a 'connection' listener. The callback will contain a Connection and a Request object:

server.on('connection', (connection, req) => {
  const userAgent = req.getHeader('User-Agent');

  console.log(`Using ${userAgent} browser`);
  connection.send('Hello world!');
});

Finally call the #listen(port) method and run your Node app:

server.listen(port).then(() => {
  console.log(`Listening on *:${port}`);
});

Methods

connection.send(data)

Sends data to the client. Depending on the type of the passed object, it will send the data in one or multiple frames:

  • Strings get sent directly in one frame.
  • Objects get converted to strings through JSON.stringify.
  • Node's Buffers get sent as binary data and may be sent in multiple frames.

connection.ping([payload])

Sends a ping frame that may contain a payload. The client must send a Pong frame with the same payload in response. Check the connection.on('pong') method for more details.

connection.close([callback])

Closes the connection.

server.broadcast(data)

Sends data to all the clients. Follows the same logic as connection.send(data)

server.getConnections()

Get an unordered array containing the current active connections.

server.close()

Closes the server. Returns a Promise that will get completed when all the connections are closed.

Events

Both the Server and the Connection are EventEmitters, so you can listen to these events:

server.on('connection', connection)

Emitted when a new connection is established. The callback arguments are connection, request, where the first is a turbo-net Connection and the later is a turbo-http Request object. Check out their docs to see what fields and methods are available.

server.on('close')

Emitted when the server has terminated all the WebSocket connections and it is going to die.

connection.on('text', string)

Emitted when the client sends some text data.

connection.on('binary', binaryStream)

Emitted when the client sends some buffered binary data. Returns a BinaryStream, which is a wrapper for Node's stream.Readable. You can then add listeners to the stream:

const writable = fs.createWriteStream('file.txt');

connection.on('binary', stream => {
  stream.pipe(writable);

  stream.on('end', () => {
    console.log('Saved client logs to disk!');
  });
});

connection.on('ping')

Emitted when the server received a Ping frame from the client.

connection.on('pong')

Emitted when the server received a Pong frame from the client.

connection.on('close')

Emitted when a connection is fully closed. No other events will be emitted after.

License

MIT © Hugo Manrique

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].