Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

205
Views
cannot connect with web socket using socket.io

I am new to javaScript. I have written 2 js files to test out web sockets.

server.js

const io = require('socket.io')(8000)

const users = {}

io.on('connection', socket => {
        console.log('new user')
})

io.on('disconnect', socket => {
    console.log("user left")
})

client.js

var socket = io('https://localhost:8000', { transports : ['websocket'] });

However, the connection cannot be established. Error messages:

chrome

WebSocket connection to 'wss://localhost:8000/socket.io/?EIO=4&transport=websocket' failed:

firefox

Firefox can’t establish a connection to the server at wss://localhost:8000/socket.io/?EIO=4&transport=websocket. 2

I am working on ubuntu 20.04

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Your server initialization is probably nit correct. You test the connectivity using ping 127.0.0.1:8000 command on shell after starting server. Try initializing server using the code below:

const { Server } = require("socket.io");

const io = new Server({ /* options */ });

io.on("connection", (socket) => {
  // ...
});

io.listen(8000);

Detaiked server initialisation info can be found at docs: https://socket.io/docs/v4/server-initialization/

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!