0

I am getting a strange error when trying to set up a nodejs - browser socket.io connection.

I've migrated out the socket.io related code to a file, here it is:

import socketIO from 'socket.io';
import https from 'https';
import express from 'express';
import fs from 'fs';

var listener,
    io;

listener =  https.createServer({
    key: fs.readFileSync('/path/to/key'),
    cert: fs.readFileSync('/path/to/crt')
}, express());


listener.listen(3200, function() {
    console.log("Listening on 3200"); 
    io = socketIO(listener, {
      rejectUnauthorized: false,
      wsEngine: "ws"
    });

    io.on('connection', function(socket){
        console.log('a user connected');
      });
});

If I run this file with node main.js, the console outputs the following message:

(node:615) ExperimentalWarning: The ESM module loader is experimental.
Listening on 3200

Now if I try to navigate with a browser to https://my.domain.name:3200, the browser outputs the following message:

Cannot GET /

And no output is received from the node server.

What could be causing this issue?

1 Answer 1

1

You have to create a web socket connection to https://my.domain.name:3200, not just go to the page. Try following https://socket.io/get-started/chat/, it will show how to serve a web page to make that connection from.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.