Variable kws

kws: {
    WsClient: typeof WsClient;
    serverClose: ((socket) => void);
    serverHandle: ((socket, buffer) => any);
    serverSend: ((socket, obj) => void);
}

Type declaration

  • WsClient: typeof WsClient
  • serverClose: ((socket) => void)
      • (socket): void
      • Parameters

        • socket: any

        Returns void

  • serverHandle: ((socket, buffer) => any)
      • (socket, buffer): any
      • Tiny server handle addon function

        Example::

        import { WebSocketServer } from 'ws'; import { kws } from 'k1js';

        const wss = new kws.WebSocketServer({ port: 8765 });

        wss.on('connection', (ws) => { console.log('Client connected');

        ws.on('message', (obj) => {
        const msg = kws.serverHandle(ws, obj) // can be undefined
        console.log(`Received message: ${msg}`);
        if (msg) kws.serverSend(ws, `modified msg (${msg})`) // optionally send a response back to the client
        // kws.serverClose(ws) // uncomment this if you want to close at any time
        });

        ws.on('close', () => {
        console.log('Client disconnected');
        });

        });

        Parameters

        • socket: any
        • buffer: any

        Returns any

  • serverSend: ((socket, obj) => void)
      • (socket, obj): void
      • Parameters

        • socket: any
        • obj: any

        Returns void

Generated using TypeDoc