Socket.io ERR_NAME_NOT_RESOLVED

I installed socket.io on my localhost and now I would look at the client / server connection. I started the server with node 'server.js'. I get this error

ERR_NAME_NOT_RESOLVED

with these simple lines of code:

SERVER:

var io = require('socket.io').listen(8080);

io.sockets.on('connection', function (socket) {
  console.log('emit...');
  socket.emit('ping', { message: 'Hello from server ' + Date.now() });
  socket.on('pong', function (data) {
    console.log(data.message);
  });
});

console.log('listening on port 8080');

CUSTOMER:

<script type="text/javascript" src="js/socket.io.js"></script>
<script>
var socket = io.connect('http:\\192.168.1.129:8080');

    socket.on('connect', function() {
     socket.emit('pong',{message:"ciaooo"});

      socket.on('ping', function (data) {
    alert(data);
  });
  });
</script>
+4
source share
1 answer

Try replacing

io.connect('http:\\192.168.1.129:8080')

with

io.connect('http://192.168.1.129:8080')
+6
source

Source: https://habr.com/ru/post/1546679/


All Articles