html5中可以这样建立连接:
var socket; //实际生产中,id可以从session里面拿用户id var id = Math.random().toString(36).substr(2); if(!window.WebSocket){ window.WebSocket = window.MozWebSocket; } if(window.WebSocket){ socket = new WebSocket("ws://118.89.129.25:1001/xiaoguo/v1/attendance"); socket.onmessage = function(event){ appendln("receive:" + event.data); }; socket.onopen = function(event){ appendln("WebSocket is opened"); login(); }; socket.onclose = function(event){ appendln("WebSocket is closed"); }; }else{ alert("WebSocket is not support"); }
请问可以在java项目中用java语言模拟这个客户端建立连接,且接受数据吗?
网上找的下面的代码只能连接固定host(118.89.129.25),那如何连接ws://118.89.129.25:1001/xiaoguo/v1/attendance 啊?小白求大神指点.
慕无忌1623718
相关分类