summaryrefslogtreecommitdiffstats
path: root/testing/xpcshell/node-ws/test/autobahn-server.js
blob: 24ade11497ff936c3a1d66b7ad2a1d2f11e82df5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
'use strict';

const WebSocket = require('../');

const port = process.argv.length > 2 ? parseInt(process.argv[2]) : 9001;
const wss = new WebSocket.Server({ port }, () => {
  console.log(
    `Listening to port ${port}. Use extra argument to define the port`
  );
});

wss.on('connection', (ws) => {
  ws.on('message', (data, isBinary) => {
    ws.send(data, { binary: isBinary });
  });
  ws.on('error', (e) => console.error(e));
});