最近我一直在使用带注释的websocket,并使用Jetty API (9.4.5 release)
进行了聊天。Jetty Websocket IdleTimeout
但是我5分钟后(我相信是默认计时器)出现问题,会话关闭(不是由于错误)。 我找到的唯一解决方案是通知我的套接字关闭事件并在新的套接字中重新打开连接。
但是我读过计算器,通过在WebsocketPolicy设置IdleTimeOut
,我可以回避的问题:
我试过设置为
3600000
的实例,但是行为不会改变时所有我也试图将其设置为
-1
但我得到以下错误:IdleTimeout [-1] must be a greater than or equal to 0
private ServletContextHandler setupWebsocketContext() { ServletContextHandler websocketContext = new AmosContextHandler(ServletContextHandler.SESSIONS | ServletContextHandler.SECURITY); WebSocketHandler socketCreator = new WebSocketHandler(){ @Override public void configure(WebSocketServletFactory factory){ factory.getPolicy().setIdleTimeout(-1); factory.getPolicy().setMaxTextMessageBufferSize(MAX_MESSAGE_SIZE); factory.getPolicy().setMaxBinaryMessageBufferSize(MAX_MESSAGE_SIZE); factory.getPolicy().setMaxTextMessageSize(MAX_MESSAGE_SIZE); factory.getPolicy().setMaxBinaryMessageSize(MAX_MESSAGE_SIZE); factory.setCreator(new UpgradedSocketCreator()); } }; ServletHolder sh = new ServletHolder(new WebsocketChatServlet()); websocketContext.addServlet(sh, "/*"); websocketContext.setContextPath("/Chat"); websocketContext.setHandler(socketCreator); websocketContext.getSessionHandler().setMaxInactiveInterval(0); return websocketContext; }
我也尝试直接在OnConnect
事件中使用调用session.getpolicy.setIdleTimeOut()
更改策略,但我没有注意到任何结果。
这是预期的行为还是我错过了什么?谢谢你的帮助。
编辑:在封闭
登录: 客户端:
2017-07-03T12:48:00.552 DEBUG [email protected] Ignored idle endpoint [email protected]{localhost/127.0.0.1:5080<->/127.0.0.1:53835,OPEN,fill=-,flush=-,to=1/300000}{io=0/0,kio=0,kro=1}->[email protected][[email protected][CLOSING,in,!out,close=CloseInfo[code=1000,reason=null],clean=false,closeSource=LOCAL],f=Flusher[queueSize=0,aggregateSize=0,failure=null],g=Generator[CLIENT,validating],[email protected][ExtensionStack,s=START,c=0,len=187,f=null]]
服务器端:
2017-07-03T12:48:00.595 DEBUG Idle pool thread onClose [email protected][[email protected][CLOSED,!in,!out,finalClose=CloseInfo[code=1000,reason=null],clean=true,closeSource=REMOTE],f=Flusher[queueSize=0,aggregateSize=0,failure=null],g=Generator[SERVER,validating],[email protected][ExtensionStack,s=START,c=0,len=2,f=CLOSE[len=2,fin=true,rsv=...,masked=true]]]<[email protected]'{'/127.0.0.1:53835<->/127.0.0.1:5080,CLOSED,fill=-,flush=-,to=1/360000000}'{'io=0/0,kio=-1,kro=-1}->[email protected][[email protected][CLOSED,!in,!out,finalClose=CloseInfo[code=1000,reason=null],clean=true,closeSource=REMOTE],f=Flusher[queueSize=0,aggregateSize=0,failure=null],g=Generator[SERVER,validating],[email protected][ExtensionStack,s=START,c=0,len=2,f=CLOSE[len=2,fin=true,rsv=...,masked=true]]]
2017-07-03T12:48:00.595 DEBUG Idle pool thread [email protected]e2 invoked org.eclipse.jetty.io.ManagedSelector$$Lambda$193/[email protected]
2017-07-03T12:48:00.595 DEBUG Idle pool thread [email protected]/[email protected]/PRODUCING/0/1 produce exit
2017-07-03T12:48:00.595 DEBUG Idle pool thread ran [email protected]/[email protected]/PRODUCING/0/1
2017-07-03T12:48:00.595 DEBUG Idle pool thread run [email protected]/[email protected]/PRODUCING/0/1
2017-07-03T12:48:00.595 DEBUG Idle pool thread [email protected]/[email protected]/PRODUCING/0/1 run
2017-07-03T12:48:00.597 DEBUG Idle pool thread 127.0.0.1 has disconnected !
2017-07-03T12:48:00.597 DEBUG Idle pool thread Disconnected: 127.0.0.1 (127.0.0.1) (statusCode= 1,000 , reason=null)
你可以发表你的日志?如果一个套接字被另一端关闭,你通常会遇到某种错误。保持活动设置也可能会影响 – ApriOri
我将编辑注释以在客户端和服务器端添加日志。 但是我没有在策略中找到任何keepalive参数。 这是Jetty Websocket API中的一件事情吗? – Youri