0.1.4 • Published 1 year ago

socket.me v0.1.4

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago
  • 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

0.1.2

1 year ago

0.1.4

1 year ago

0.1.3

1 year ago

0.0.51

1 year ago

0.0.50

1 year ago

0.0.46

2 years ago

0.0.44

2 years ago

0.0.43

2 years ago

0.0.42

2 years ago

0.0.41

2 years ago

0.0.40

2 years ago

0.0.38

2 years ago

0.0.37

2 years ago

0.0.36

2 years ago

0.0.35

2 years ago

0.0.34

2 years ago

0.0.33

2 years ago

0.0.32

2 years ago

0.0.31

2 years ago

0.0.30

2 years ago

0.0.29

2 years ago

0.0.28

2 years ago

0.0.27

2 years ago

0.0.26

2 years ago

0.0.25

2 years ago

0.0.24

2 years ago

0.0.23

2 years ago

0.0.22

2 years ago

0.0.21

2 years ago

0.0.20

2 years ago

0.0.19

2 years ago

0.0.18

2 years ago

0.0.17

2 years ago

0.0.16

2 years ago

0.0.15

2 years ago

0.0.14

2 years ago

0.0.13

2 years ago

0.0.12

2 years ago

0.0.11

2 years ago

0.0.10

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago