How to use the ws.Socket function in ws

To help you get started, we’ve selected a few ws examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github fibjs / fib-app / test / chat.js View on Github external
it('performance', () => {
        var conns = [];

        for (var i = 0; i < 200; i++) {
            var conn = new ws.Socket('ws://127.0.0.1:8080/push');
            conn.onopen = function () {
                this.send(JSON.stringify({
                    act: "on",
                    ch: `channel_${cid}`,
                    timestamp: 0
                }));
            }

            conns.push(conn);
        }

        coroutine.sleep(1000);

        console.time('chat performance');
        coroutine.parallel(() => {
            for (var i = 0; i < 100; i++) {
github fibjs / fib-app / test / chat.js View on Github external
it('push', () => {
        var conn = new ws.Socket('ws://127.0.0.1:8080/push');
        conn.onopen = () => {
            conn.send(JSON.stringify({
                act: "on",
                ch: `channel_${cid}`,
                timestamp: 0
            }));
        }

        var r = [];

        conn.onmessage = m => {
            r.push(m.json());
        };

        coroutine.sleep(100);
github fibjs / fibjs / test / process / exec18.js View on Github external
var ws = require('ws');

process.exitCode = 18;

var conn = new ws.Socket("ws://999.99.999.999/not_exists");
conn.onerror = e => {
    process.exitCode = 81;
}
github fibjs / fib-app / demo / defs / chat / spec.js View on Github external
it('performance', () => {
        var conns = [];

        for (var i = 0; i < 200; i++) {
            var conn = new ws.Socket(wsBase + '/push');
            conn.onopen = function () {
                this.send(JSON.stringify({
                    act: "on",
                    ch: `channel_${cid}`,
                    timestamp: 0
                }));
            }

            conns.push(conn);
        }

        coroutine.sleep(1000);

        console.time('chat performance');
        coroutine.parallel(() => {
            for (var i = 0; i < 100; i++) {
github fibjs / fib-app / demo / defs / chat / spec.js View on Github external
it('push', () => {
        var conn = new ws.Socket(wsBase + '/push');
        conn.onopen = () => {
            conn.send(JSON.stringify({
                act: "on",
                ch: `channel_${cid}`,
                timestamp: 0
            }));
        }

        var r = [];

        conn.onmessage = m => {
            r.push(m.json());
        };

        coroutine.sleep(100);

ws

Simple to use, blazing fast and thoroughly tested websocket client and server for Node.js

MIT
Latest version published 6 months ago

Package Health Score

89 / 100
Full package analysis