qq_38209362
qq_38209362
2017-09-10 03:33

websocket问题 ,请大神指教

  • websocket

初学websocket 为什么访问一直不对啊 代码贴出来

<script type="text/javascript">
    function subOpen(){
    var ws;
    var target="ws://localhost:8080/websocket/demo";
     if ('WebSocket' in window) {
            ws = new WebSocket(target);
        } else if ('MozWebSocket' in window) {
            ws = new MozWebSocket(target);
        } else {
            alert('WebSocket is not supported by this browser.');
            return;
        }
}
</script>
-----------------------------------------
@ServerEndpoint("/demo")

public class DemoSocket {
@OnOpen
public void open(Session session){
System.out.println(session.getId()+"--------------");
}
}

打印不出来。。。

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

2条回答