Skip to content

Instantly share code, notes, and snippets.

@TobiahRex
Created October 26, 2018 06:48
Show Gist options
  • Save TobiahRex/0faeb9090310b03219ef278f94c92671 to your computer and use it in GitHub Desktop.
Save TobiahRex/0faeb9090310b03219ef278f94c92671 to your computer and use it in GitHub Desktop.
var express = require('express')
var app = express()
var http = require('http').Server(app)
app.use(express.static(__dirname))
app.get('/', function(req,res){
res.sendFile(__dirname + '/index.html')
})
const WebSocket = require('ws');
const socketConnection = new WebSocket.Server({
port: 4000,
server: false
});
console.log(socketConnection);
socketConnection.on('connection', function connection(ws) {
ws.on('message', function incoming(message) {
console.log(message);
console.log("works");
});
ws.on('close', function close() {
console.log('disconnected');
});
});
console.log(WebSocket.readyState);
http.listen(3000, function(){
console.log('Listening on *:3000');
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment