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

338
Views
WebSocket - can't connect (Expected HTTP/)

I am using Node.JS and I am using http to use an express server which then my WebSocket is on, but when I try to connect to the socket it gives me an 'Expected HTTP/' error.

Error

My code:

const express = require('express');
const app = express();
const server = require('http').createServer(app);

app.get('/', (req, res) => {
    res.send("Hello World!");
});

const wss = new WebSocket.Server({ server });
// web socket stuff here

server.listen(port, () => {
    console.log(`HTTP Server started on port ${port}`);
});

And then on another Node project, I have this to connect:

const WebSocket = require('ws');
const ws = new WebSocket.WebSocket('ws://localhost:3000/ws');

Any help?

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

0

//my memory in this question was that

const WebSocket = require('ws');
const socket = new WebSocket.Server({ port: 2424, host: "localhost"});

socket.on('connection', function(ws, wss) {
    
  var domain = wss.headers.origin;

//etc...

But maybe you have a front for communicate if is not the good response ?

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!