ws.on('open', function open() { if (/checkStatusCode/.test(url)) { if (done) { return; } done = true; callback && callback('checkStatusCode'); exit(); } else { ws.send('something'); } });
wss.on('connection', function connection(ws) { var req = ws.upgradeReq; ws.on('message', function(msg) { ws.send(JSON.stringify({ type: 'server', method: req.method, headers: req.headers, body: msg }, null, '\t')); }); });
/** * @param {string} message */ send(message) { if (this._ws.readyState === WebSocket.OPEN) { protocolDebug('>', message); this._ws.send(message); } }
this.wss.on("connection", ws => { this.onopened(this.tty._pid); ws.on("close", (code, reason) => { this.ondisconnected(code, reason); }); ws.on("message", msg => { this.tty.write(msg); }); this.tty.onData(data => { this._nextTickUpdateTtyCWD = true; this._nextTickUpdateProcess = true; try { ws.send(data); } catch (e) { // Websocket closed } }); });
async _startSession(info, frontend) { const ws = new WebSocket(info.inspectorUrl); const openPromise = new Promise(resolve => ws.once('open', () => resolve(DebugState.WS_OPEN))); const errorPromise = new Promise(resolve => ws.once('error', () => resolve(DebugState.WS_ERROR))); const closePromise = new Promise(resolve => ws.once('close', () => resolve(DebugState.WS_CLOSE))); let state = await Promise.race([openPromise, errorPromise, closePromise, this._disconnectPromise]); if (state === DebugState.WS_OPEN) { this._connected.add(info.id); const channel = new Channel(ws); state = await Promise.race([frontend.detected(info, rpc.handle(channel)), this._disconnectPromise]); return async() => { if (state !== DebugState.PROCESS_DISCONNECT) state = await Promise.race([closePromise, errorPromise, this._disconnectPromise]); channel.dispose(); this._connected.delete(info.id); if (state !== DebugState.PROCESS_DISCONNECT) frontend.disconnected(info.id); else ws.send(CALL_EXIT_MESSAGE, () => ws.close()); }; } else { return async function() {}; } }
ws.send('something'); }); var done;
wss.on('connection', function connection(ws) { ws.on('message', function incoming(message) { ws.send(message); }); });
function run() { if (times > num_requests) { return; } if (times == num_requests) { var now = Date.now(); var cost = now - start; console.log('run %d num requests cost: %d ops/sec', num_requests, cost, (num_requests / (cost / 1000)).toFixed(2)); times = 0; start = now; return run(); } times++; var payload = "hello"; ws.send(JSON.stringify({ topic: "topic", payload: payload, qos: 1, messageId: times })); }
this.socket.send(byte.buffer);
this.socket.send(byte.buffer);
/** * Throttled call to ws.send, max 8 op/s * * @param {Array} msg - message * @private */ _sendCalc (msg) { debug('req calc: %j', msg) this._ws.send(JSON.stringify(msg)) }
this.wss.on("connection", ws => { this.onopened(this.tty._pid); ws.on("close", (code, reason) => { this.ondisconnected(code, reason); }); ws.on("message", msg => { this.tty.write(msg); }); this.tty.onData(data => { this._nextTickUpdateTtyCWD = true; this._nextTickUpdateProcess = true; try { ws.send(data); } catch (e) { // Websocket closed } }); });
wss.on('connection', function connection(ws) { ws.on('message', function incoming(message) { ws.send(message); }); });
function run() { if (times > num_requests) { return; } if (times == num_requests) { var now = Date.now(); var cost = now - start; console.log('run %d num requests cost: %d ops/sec', num_requests, cost, (num_requests / (cost / 1000)).toFixed(2)); times = 0; start = now; return run(); } times++; var payload = "hello"; ws.send(JSON.stringify({ topic: "topic", payload: payload, qos: 1, messageId: times })); }
this.socket.send(byte.buffer);