Answer the question
In order to leave comments, you need to log in
Why is React not connecting via socket.io?
There is a react code like this:
import io from 'socket.io-client';
const socket = io('http://localhost:3000');
socket.on('connect', (d) => {
socket.emit('new_connection', document.location.href.split('?')[1].replace(document.location.hash, ''))
})
var app = express()
var http = require('http').createServer(app)
var io = require('socket.io')(http)
io.on('connection', (socket) => {
socket.on('new_connection', () => {
console.log('ok')
})
});
http.listen(3000, () => {
console.log('listening on *:3000')
})
'http://localhost:3000'
just trying to write, both the url and the ip of the machine do not want to connect. What could be the problem?
Answer the question
In order to leave comments, you need to log in
1) Check the path on the ws connection, maybe you left localhost somewhere =)
2) Check if the server is turned on on the server (for example, create a test get-request and throw it with Ajax)
I think the problem is in the addresses. If there is an error on ws, then please throw it in the comments!)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question