Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Socket io client cannot communicate to socket io server

former_member916394
Discoverer
0 Likes
1,000

Need your help/guidance/suggestion for our scenario.

Issue: I am having some trouble connecting socket io client to socket io server. The error I got after running this code is connection time out. My html code is running at 5000 port and server at 4004.

How to connect socket running at different ports.

My server code is :

<code>const port = process.env.PORT || 4004;
const http = require('http');
const socket = require('socket.io');
const app = express();
const httpServer = http.createServer(app);
const io = new socket.Server(httpServer);

io.on('connection', (socket) => {
    console.log("Socket connected");
});

httpServer.listen(port, () => {
    console.log("Listening on port ",port);
});

Html code is:

<script src = "socket.io.min.js"> </script>
<script>
    var socket = io.connect(`wss://${document.location.hostname}:${port}`);
    console.log(socket);
    socket.on('done', (data) => {
        console.log(data);
    });
 </script>
0 REPLIES 0