我想利用Easy Websockets来创建一个聊天应用程序。 http://easywebsocket.org/如何使用网络套接字
这是我现在的代码。正如你所看到的,我试图在每次点击发送按钮时在控制台上记录消息。它在2个浏览器上打开时起作用。但它只能运行不到1分钟。
<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>
我从萤火这个错误日志:
我真的不明白这是什么一切手段。有什么我需要设置为了使这项工作?
我目前也在玩[Easy Web Socket](http://easywebsocket.org/)并得到相同的错误,但我不明白解决方案...因为他们ar e说'你想使用websockets?你想把消息广播给所有连接的客户端?你不想担心浏览器的兼容性?你不想建立一个服务器?以下是您需要的所有代码。“那么,您是如何通过** Easy Web Socket **来解决问题的,或者您只是使用其他方法? – Taifun 2012-12-29 21:45:20