具体情况是这个web应用在本地调试没有任何问题,放在服务器里的话,虽然也可以连接的上,但是同样的请求却没有反应
比如在客户端发送指令
{"room":"22","action":"join"}
本地日志
18-01-14 10:39:29.577 DEBUG [qtp1052399527-105] session(id=oo497ncjrsio5qhc661oeullf8) join room(name=22)
服务器日志
2018-01-14 10:38:06.467:INFO:oejs.Server:main: Started @4833ms
18-01-14 10:41:53.829 DEBUG [qtp1451043227-11] Search mapping for [GET] path=/websocket : NOT Action match
18-01-14 10:41:53.861 DEBUG [qtp1451043227-11] Get 'webSocketModule'<class ycu.ktv.module.WebSocketModule>
18-01-14 10:41:53.861 DEBUG [qtp1451043227-11] Get '$aop_async'<interface org.nutz.ioc.aop.config.AopConfigration>
18-01-14 10:41:53.861 DEBUG [qtp1451043227-11] >> Load definition name=$aop_async
18-01-14 10:41:53.876 DEBUG [qtp1451043227-11] Found IocObject($aop_async) in AsyncAopIocLoader@1572394049
18-01-14 10:41:53.876 DEBUG [qtp1451043227-11] >> Make...'$aop_async'<interface org.nutz.ioc.aop.config.AopConfigration>
18-01-14 10:41:53.876 DEBUG [qtp1451043227-11] Save object '$aop_async' to [app]
18-01-14 10:41:53.876 DEBUG [qtp1451043227-11] Load AopConfigure for anno=org.nutz.ioc.aop.Aop by type=org.nutz.ioc.aop.config.impl.AnnotationAopConfigration
18-01-14 10:41:53.876 DEBUG [qtp1451043227-11] >> Load definition name=webSocketModule
18-01-14 10:41:53.876 DEBUG [qtp1451043227-11] Found IocObject(webSocketModule)in AnnotationIocLoader(packages=[ycu.ktv.module])
18-01-14 10:41:53.892 DEBUG [qtp1451043227-11] >> Make...'webSocketModule'<class ycu.ktv.module.WebSocketModule>
18-01-14 10:41:53.892 DEBUG [qtp1451043227-11] Load class ycu.ktv.module.WebSocketModule without AOP
18-01-14 10:41:53.892 DEBUG [qtp1451043227-11] Save object 'webSocketModule' to[app]
就是无论怎么发送都没反应,而且没效果
但是如果使用@onMessage注解就可以获取发送的消息
这是代码
package ycu.ktv.module;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.lang.Each;
import org.nutz.lang.util.NutMap;
import org.nutz.plugins.mvc.websocket.AbstractWsEndpoint;
import org.nutz.plugins.mvc.websocket.NutWsConfigurator;
import org.nutz.plugins.mvc.websocket.WsHandler;
import org.nutz.plugins.mvc.websocket.handler.SimpleWsHandler;
import javax.websocket.EndpointConfig;
import javax.websocket.OnMessage;
import javax.websocket.Session;
import javax.websocket.server.ServerEndpoint;
// ServerEndpoint是websocket的必备注解, value是映射路径, configurator是配置类.
@ServerEndpoint(value = "/websocket", configurator = NutWsConfigurator.class)
@IocBean // 使用NutWsConfigurator的必备条件
public class WebSocketModule extends AbstractWsEndpoint {
@Override
public WsHandler createHandler(Session session, EndpointConfig config) {
return new MySimpleWsHandler();
}
public class MySimpleWsHandler extends SimpleWsHandler {
public MySimpleWsHandler() {
super(""); // 覆盖默认前缀
}
public void msg2room(final NutMap req) {
final String room = req.getString("room");
if (room != null) {
String _room = room;
if (this.prefix.length() > 0 && !room.startsWith(this.prefix)) {
_room = this.prefix + room;
}
this.endpoint.each(_room, new Each<Session>() {
public void invoke(int index, Session ele, int length) {
if (!ele.getId().equals(MySimpleWsHandler.this.session.getId())) {
NutMap resp = new NutMap("action", "msg");
resp.setv("room", room);
resp.setv("timestamp", System.currentTimeMillis());
resp.setv("msg", req.get("msg"));
if (MySimpleWsHandler.this.nickname != null) {
resp.setv("nickname", MySimpleWsHandler.this.nickname);
}
MySimpleWsHandler.this.endpoint.sendJson(ele.getId(), resp);
}
}
});
}
}
}
}
------------
websocket插件使用版本 1.r.63.r5
本地jetty版本9.4.5.v20170502
服务器jetty版本9.4.5.v20170502