我正在编写一个html需要创建websocket到服务器的页面在服务器上,我使用了“code.google.com/p/go.net/websocket”中的示例,只接受连接。但是,在 Chrome26 中,响应是与“ws://127.0.0.1:1234/”的 WebSocket 连接失败:意外响应代码:400是否遗漏了什么(如握手)?这是我的html服务器正在使用go<html><head></head><body><script type="text/javascript"> var sock = null; var wsuri = "ws://127.0.0.1:1234"; window.onload = function() { console.log("onload"); sock = new WebSocket(wsuri); sock.onopen = function() { console.log("connected to " + wsuri); } sock.onclose = function(e) { console.log("connection closed (" + e.code + ")"); } sock.onmessage = function(e) { console.log("message received: " + e.data); } }; function send() { var msg = document.getElementById('message').value; sock.send(msg); };</script><h1>WebSocket Echo Test</h1><form> <p> Message: <input id="message" type="text" value="Hello, world!"> </p></form><button onclick="send();">Send Message</button></body></html>
1 回答
- 1 回答
- 0 关注
- 381 浏览
添加回答
举报
0/150
提交
取消