问题描述
网上的怎么测试都搞不好求个demo我是tomcat7.0.47
解决方案
解决方案二:
我抓的包跟别人都不一样
解决方案三:
//代码java的packagecom.socket;importjavax.websocket.OnClose;importjavax.websocket.OnMessage;importjavax.websocket.OnOpen;importjavax.websocket.Session;importjavax.websocket.server.PathParam;importjavax.websocket.server.ServerEndpoint;@ServerEndpoint(value="/websocket/{user}")publicclassMyWebSocket{privateSessionsession;@OnOpenpublicvoidopen(Sessionsession,@PathParam(value="user")Stringuser){this.session=session;System.out.println(session.getId()+"登陆");}@OnMessagepublicvoidinMessage(Stringmessage){//sysLogger.info("***WebSocketReceivedfromsessionId"+this.session.getId()+":"+message);System.out.println(session.getId()+"说:"+message);}@OnClosepublicvoidclose(){System.out.println(session.getId()+"离开");}}
解决方案四:
<%@pagelanguage="java"import="java.util.*"pageEncoding="UTF-8"%><%Stringpath=request.getContextPath();StringbasePath=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%><!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN"><html><head><basehref="<%=basePath%>"><title>MyJSP'index.jsp'startingpage</title><metahttp-equiv="pragma"content="no-cache"><metahttp-equiv="cache-control"content="no-cache"><metahttp-equiv="expires"content="0"><metahttp-equiv="keywords"content="keyword1,keyword2,keyword3"><metahttp-equiv="description"content="Thisismypage"><!--<linkrel="stylesheet"type="text/css"href="styles.css">--><scripttype="text/javascript">varsocket;functionstartwebsocket(){if('WebSocket'inwindow){socket=newWebSocket("ws://locathost:8080/WebSocketDemo/websocket/{user}");}elseif('MozWebSocket'inwindow){socket=newWebSocket("ws://locathost:8080/WebSocketDemo/websocket/{user}");}else{alert("该浏览器不支持");}socket.onmessage=function(evt){alert(evt.data);}socket.onclose=function(evt){alert("close");}socket.onopen=function(evt){alert("open");}socket.onerror=function(evt){alert("error");}}functionsendMsg(){ws.send(document.getElementById('writeMsg').value);}</script></head><body><bodyonload="startwebsocket();"><inputtype="text"id="writeMsg"></input><inputtype="button"value="send"onclick="sendMsg()"></input></body></body></html>
解决方案五:
我只用Socket和ServerSocket写过Websocket服务器,javax的没用过。。你具体是什么问题?
解决方案六:
引用4楼vnvlyp的回复:
我只用Socket和ServerSocket写过Websocket服务器,javax的没用过。。你具体是什么问题?
协议出错
解决方案七:
用的框架playwebsocket
解决方案八:
引用6楼huxiweng的回复:
用的框架playwebsocket
能说详细点吗最好有例子