Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

socket.io ERR_NAME_NOT_RESOLVED

Tags:

socket.io

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>
like image 290
user3682770 Avatar asked Jul 01 '14 12:07

user3682770


People also ask

Why is Socket.IO not connecting?

Problem: the socket is not able to connect​You are trying to reach a plain WebSocket server. The server is not reachable. The client is not compatible with the version of the server. The server does not send the necessary CORS headers.

How do I connect Socket.IO With react?

Navigate into the client folder via your terminal and create a new React. js project. Install Socket.io client API and React Router. React Router is a JavaScript library that enables us to navigate between pages in a React application.


1 Answers

Try to replace

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

with

io.connect('http://192.168.1.129:8080')
like image 79
Oleg Avatar answered Oct 01 '22 00:10

Oleg



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!