0

I'm trying to set up a simple server/client architecture using socket.io.

I have the following code in my main.js

var app = require('express')(); var http = require('http').createServer(app); var io = require('socket.io')(http); app.get('/', (req, res) => { res.send('<h1>Hello world</h1>'); }); io.on('connection', function(socket){ console.log('a user connected') }) http.listen(3001, () => { console.log('listening on *:3001'); }); 

I have the following code in my client.js

const io = require("socket.io-client"); let socket = io(':3001') 

I then run node main.js which prints "listening on *:3001", however when I run node client.js the expected "a user connected" is not printed. What am I missing in this simple architecture?

1 Answer 1

1

It should work if you write it like this in your client.js:

let socket = io('http://localhost:3001/')

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.