level 2
客户端请求建立websocket连接时apache服务器响应,并作出实时响应。请教服务器端源码怎么写?相关教程?
2014年09月14日 03点09分
1
level 12
apache应没办法实作websocket。
需要的是像node.js的socket.io或
ruby的em-websocket
python的ws4py 等,
及其他各编程语言有关websocket的实作,
来建立websocket端的服务。
2014年09月14日 14点09分
2
![[哈哈]](/static/emoticons/u54c8u54c8.png)
谢谢你!正在学Node了~
2014年09月15日 00点09分
level 1
下载一个webSocket包然后把我后面的代码加上
@ServerEndpoint(value="/websocket/{puid}")
public class WebsocketTest {
public WebsocketTest(){
System.out.println("WebsocketTest..");
}
//加载服务器的时候回调用
@OnOpen
public void onopen(Session session,@PathParam("puid") String puid){
try {
session.getBasicRemote().sendText(puid+"这是服务器发送的消息");
} catch (IOException e) {
e.printStackTrace();
}
}
//服务器关闭的时候回调用
@OnClose
public void onclose(Session session){
System.out.println("close....");
}
//收到消息的时候回调用
@OnMessage
public void onsend(Session session,String msg){
try {
session.getBasicRemote().sendText("client"+session.getId()+"say:"+msg);
System.out.println(msg);
} catch (IOException e) {
e.printStackTrace();
}
}
访问的时候 ws://你的ip加端口号/你的项目路径/前面的注解websocket/{puid}({puid})是我开发需要 你可以不加
2017年11月13日 06点11分
3