How to use network sockets

I am trying to use Easy Websockets to come up with a chat application. http://easywebsocket.org/

Here is the code I have right now. As you can see, I am trying to log a message to the console every time I hit the submit button. It works when I open it on two browsers. But it only works for less than 1 minute.

<input type="text" id="txt"/>
<input type="button" value="send" id="sends"/>
<div id="messages"></div>

<script src="jquery171.js"></script>
<script src="easywebsockets.js"></script>   
<script>
    var socket = new EasyWebSocket("ws://sample.com/resource");//I do not understand this part
    socket.onopen   = function(){
        socket.send("hello world.")
    }
    socket.onmessage= function(event){
        console.log(event.data)
    }

    $('#sends').click(function(){
        var txt = $('#txt').val()
        socket.send(txt)
    });
</script>

      

I got this error log from firebug:

enter image description here

I don't quite understand what this all means. Is there something I need to set up to make this work?

+3


source to share


1 answer


This usually happens when the client is not using the same version of the protocol as the server. The server should indicate which version it is using, socket.io comes with RFC6455 by default, but it can be overridden to go with the old hybi-0x.

So check the following:



  • client and server versions of the protocol
  • origin (e.g. localhost) resolved by server
  • firewalls, internet security kits, zonealarms, stuff like that
+1


source







All Articles