socket.io ERR_NAME_NOT_RESOLVED

2019-04-28 03:20发布

I have installed socket.io on my localhost and now I would view a client/server communication. I have started the server with node 'server.js'. I get this error

ERR_NAME_NOT_RESOLVED

with this 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');

CLIENT:

<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>

标签: socket.io
1条回答
迷人小祖宗
2楼-- · 2019-04-28 03:57

Try to replace

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

with

io.connect('http://192.168.1.129:8080')
查看更多
登录 后发表回答