Giter VIP home page Giter VIP logo

socket.me's Introduction

  • 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

socket.me's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.