socket.me
TypeScript icon, indicating that this package has built-in type declarations

0.1.4 • Public • Published
  • Binary
  • Relative and absolute zero-copy operations wherever possible

Goals:

  1. Low memory usage;
  2. Maximum performance;
  3. Flexibility;
  4. Security (politic-free).

Server:

const mio = SocketMe({
    idleTimeout: 16,
    maxPayloadLength: 512
});

//---]>

mio.onConnection((socket) => {
    socket.subscribe('all');
    
    socket.on('message', (text, callback) => {
        callback(`${text} world`);
        socket.emit('someEvent', text);
        mio.publish('all', 'someEvent', text);
    });
});

//---]>

mio.listen(3500);

Client (WebApp):

const ws = mio('localhost:3500');

//---]>

ws.onConnect(() => {
    const sent = ws.emit('message', 'hello', (r) => console.log(r), 2000/*[timeout]*/);
});

ws.on('someEvent', (data) => {});

Browser:

const mio = SocketMe({
    useClientLib: true, 
 // clientLibPath: 'socket.me_myPath'
});
<script src="http://localhost:3500/socket.me"></script>

Nuxt.js:

import { Mio } from 'socket.me/types/client.d';
import client from 'socket.me/client';

//---]>

const ws = client as Mio;

Typed (Server):

// any, number, string, boolean, array, object (only { ... })

mio.onConnection((socket) => {
    socket
        .typed({
            id: (v) => typeof v === 'number',
            name: 'string',
            tags: 'array'
        })
        .on('object', ({ id, name, tags }) => {
            console.log('object:', id, name, tags);
        });

    socket
        .typed(['number', 'string', 'array'])
        .on('array', ([id, name, tags]) => {
            console.log('array:', id, name, tags);
        });

    socket
        .typed('number')
        .on('primitive', (id) => {
            console.log('primitive:', id);
        });
});

Protocol:

[ mode (u8), typeLen (u8), type (str), [ack (u8)], [data (bin|str)] ]
[ 0-255, 0-255, ..., 0-255, ... ]

C_MODE_BIN   = 1
C_MODE_JSON  = 2
C_MODE_ACK   = 4
C_MODE_EMPTY = 8

License

MIT

Package Sidebar

Install

npm i socket.me

Homepage

666.io

Weekly Downloads

0

Version

0.1.4

License

MIT

Unpacked Size

120 kB

Total Files

42

Last publish

Collaborators

  • daeren