Skip to content
Snippets Groups Projects
Commit a0239b2c authored by Magnus Sten Andersen's avatar Magnus Sten Andersen
Browse files

test websocketserver

parent 7c4fef2c
No related branches found
No related tags found
No related merge requests found
node_modules/
\ No newline at end of file
'use strict'
const WebSocket = require('ws')
let ws = new WebSocket('ws://localhost:8080')
ws.onopen = function () {
console.log('open')
ws.send('hello')
}
{
"name": "server",
"version": "1.0.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"async-limiter": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/async-limiter/-/async-limiter-1.0.0.tgz",
"integrity": "sha512-jp/uFnooOiO+L211eZOoSyzpOITMXx1rBITauYykG3BRYPu8h0UcxsPNB04RR5vo4Tyz3+ay17tR6JVf9qzYWg=="
},
"ws": {
"version": "6.2.1",
"resolved": "https://registry.npmjs.org/ws/-/ws-6.2.1.tgz",
"integrity": "sha512-GIyAXC2cB7LjvpgMt9EKS2ldqr0MTrORaleiOno6TweZ6r3TKtoFQWay/2PceJ3RuBasOHzXNn5Lrw1X0bEjqA==",
"requires": {
"async-limiter": "~1.0.0"
}
}
}
}
{
"name": "server",
"version": "1.0.0",
"description": "",
"main": "server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node server.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"ws": "^6.2.1"
}
}
var port = 8080
var WebSocketServer = require('ws').Server
var wss = new WebSocketServer({ port: port })
console.log('listening on port: ' + port)
wss.on('connection', function connection (ws) {
ws.on('message', function (message) {
console.log('message: ' + message)
ws.send('echo: ' + message)
})
console.log('new client connected!')
ws.send('connected!')
})
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment