Sunday 21 May 2017

Socket.IO and express unable to connect

I'm trying to build a simple signaling server for WebRTC using Socket.IO and Express. I've never used Express or Socket.IO before so I figure I'd just run through a couple examples (using ES6). Not surprisingly, I'm running into trouble just connecting to the server. Can anyone advise? Here is my very basic server straight from the docs, modified to ES6 using https://github.com/riebel/socketio-es6-starter as a guide.

import http from 'http';
import express from 'express'
import SocketIO from 'socket.io'

let app = express();
let server = http.Server(app);
let io = new SocketIO(server);

app.get('/', (req, res) =>{
    res.send('hi');
});

io.on('connection', (socket) => {
    "use strict";
   socket.emit('news', {hello: 'world'});
   socket.on('my other event', (data) => {
       console.log(data)
   })
});

server.listen(80, () => {
    "use strict";
    console.log('Listening on port 80');
});

I'm using the wscat utility from npm and every time I try to connect I just get this: enter image description here

I've tried using the DEBUG environment variable but it doesn't seem to do much. I also tried doing ws://localhost:80/socket.io as per that last line but it didn't work: enter image description here



via coolboyjules

No comments:

Post a Comment