0

I've wrote a simple node.js app by socket.io some weeks ago. My program is fine on my PC but when i tried to run it on my laptop. I faced a really weird error on my console.
note that I'm running node on 127.0.0.1:2324. I don't know what is that ip (0.0.9.20) on the chrome console.

Again, my code is correct cause it's working fine on my PC.

enter image description here
And I get this on my cmd:

enter image description here
my paint.html code is something like this:

<script src="http://127.0.0.1/node/paint/js/jquery.js"></script>
<script src="http://127.0.0.1/node/paint/js/cursor.js"></script>
<script src="http://127.0.0.1/node/paint/js/controllers.js"></script>
<script src="http://127.0.0.1/node/paint/js/core.js"></script>
<script src="http://127.0.0.1:2324/socket.io/socket.io.js"></script>
<link  href="http://127.0.0.1/node/paint/css/style.css" rel="stylesheet" />

core.js:

// broadcat function
    function broadcast(data)
    {
        var socketio = io.connect(serverPort);
        socketio.emit("message_to_server", { pen : data});
    }

    // receive data from server
    var socketio = io.connect(serverPort);
    socketio.on("message_to_client", function(data) 
    {
        var res_brush = data['pen'];
        var brush_data_rec = res_brush['pen'].split('|');
        draw(brush_data_rec[0],
             brush_data_rec[1],
             brush_data_rec[2],
             brush_data_rec[3],
             brush_data_rec[4],
             brush_data_rec[5],
             brush_data_rec[6]);
    });

update:
enter image description here

2
  • @hexacyanide I've updated the question. It's 2.33 am in here. and I have to represent it on 9 am. I'm a bit in hurry :( Commented Sep 29, 2013 at 23:06
  • If someone vote up my question. I would have enough reputation to set a bounty on my question. Commented Sep 29, 2013 at 23:08

1 Answer 1

3

You should explicitly specify the target hostname on the client to connect to to avoid confusing the client on which address to connect to. There's also a cleaner way to specify a target port.

var socket = io.connect('http://localhost/', {
  'port': 8080,
  'transports': ['websockets']
});
Sign up to request clarification or add additional context in comments.

6 Comments

Thanks for the answer it disappeared the console error but the functionality problem is still there. I get new error on cmd see the update.
It's falling back to XHR polling because websockets aren't working. Try restricting the transport options. I'll edit my post with it.
It's working you are a genius. Thanks. can you explain more about this property 'transports': ['websockets'] ?
Socket.IO is a multi-transport library, so if websockets fail, then it falls back to other things such as JSONP polling or XHR long-polling. By setting the only allowed transport to websockets, we prevent any fallback to other transports which were not working for you.
The debug you were seeing in console actually wasn't errors, it was just debug. I was referring to anything else that might have also been failing to work.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.