File tree Expand file tree Collapse file tree 2 files changed +16
-16
lines changed
Expand file tree Collapse file tree 2 files changed +16
-16
lines changed Original file line number Diff line number Diff line change 11#! /bin/bash
22
33# Start the WebSocket server in the background
4- node -e "
5- const ws = require('nodejs-websocket');
6- ws.createServer(function (conn) {
7- conn.on('text', function (msg) {
8- if (msg.startsWith('echo:')) {
9- conn.sendText(msg.replace('echo:', ''));
10- } else if (msg.startsWith('close:')) {
11- const code = msg.replace('close:', '');
12- conn.close(parseInt(code), 'reason');
13- }
14- });
15- conn.on('error', function (error) {
16- if (error.code !== 'ECONNRESET') throw error;
17- });
18- }).listen(7999, () => console.log('WebSocket server ready'));
19- " &
4+ node test/websocket-server.js &
205
216SERVER_PID=$!
227
Original file line number Diff line number Diff line change 1+ import ws from 'nodejs-websocket'
2+
3+ ws . createServer ( function ( conn ) {
4+ conn . on ( 'text' , function ( msg ) {
5+ if ( msg . startsWith ( 'echo:' ) ) {
6+ conn . sendText ( msg . replace ( 'echo:' , '' ) )
7+ } else if ( msg . startsWith ( 'close:' ) ) {
8+ const code = msg . replace ( 'close:' , '' )
9+ conn . close ( parseInt ( code ) , 'reason' )
10+ }
11+ } )
12+ conn . on ( 'error' , function ( error ) {
13+ if ( error . code !== 'ECONNRESET' ) throw error
14+ } )
15+ } ) . listen ( 7999 )
You can’t perform that action at this time.
0 commit comments