socket.io 404 error: socket.io/?transport=polling&t=OUFK089

28 Views Asked by At

I have recently heard of socket.io, so I wanted to try it out on the hosting service I have at hand after a successful attempt using localhost, but instead of it working, now it just displays this error in the client console: https://example.com/socket.io/?transport=polling&t=OUFK089, and I have just been struggling here for the last few days, I have been searching the internet for a answer to my problem, and everywhere I see people who manage to fix it but me not being able to. Here is the server code:

const express = require('express');
const app = express();
const http = require('http');
const server = http.createServer(app);
const { Server } = require("socket.io");
const io = new Server(server);

server.listen(3000, () => {
  console.log('listening on *:3000');
  io.on("connection", function (socket) {
    console.log("User connected: " + socket.id);
  });
});

And here is the client html:

<!DOCTYPE html>
<html>
  <head>
    <title>Zesty testy</title>
  </head>
  <body>
    <script src="https://cdn.socket.io/4.6.1/socket.io.js"></script>
    <script src="./client.js"></script>
  </body>
</html>

..client.js:

var socket = io("https://example.com/"); 

And I have been mindlessly changing the code here and there trying to get it to work. And I come here once again trying to get a more insight answer. I think I should mention that where I'm running the server js file from is https://example.com/foobar/index.js.

I am expecting it to return 200 and display in the server console that a user has connected with their ID.

0

There are 0 best solutions below