最近很多小伙伴都在问javax.websocket.RemoteEndpoint.Async的实例源码和javasocket源码这两个问题,那么本篇文章就来给大家详细解答一下,同时本文还将给你拓展C#
最近很多小伙伴都在问javax.websocket.RemoteEndpoint.Async的实例源码和java socket源码这两个问题,那么本篇文章就来给大家详细解答一下,同时本文还将给你拓展C# WebSocket SendAsync 异常、io.netty.handler.codec.http.websocketx.PongWebSocketFrame的实例源码、io.netty.handler.codec.http.websocketx.WebSocketClientHandshaker的实例源码、Java WebSockets: The remote endpoint was in state [TEXT_FULL_WRITING]等相关知识,下面开始了哦!
本文目录一览:- javax.websocket.RemoteEndpoint.Async的实例源码(java socket源码)
- C# WebSocket SendAsync 异常
- io.netty.handler.codec.http.websocketx.PongWebSocketFrame的实例源码
- io.netty.handler.codec.http.websocketx.WebSocketClientHandshaker的实例源码
- Java WebSockets: The remote endpoint was in state [TEXT_FULL_WRITING]
javax.websocket.RemoteEndpoint.Async的实例源码(java socket源码)
/** * * @see com.tsystems.readyapi.plugin.websocket.Client#sendMessage(com.tsystems.readyapi.plugin.websocket.Message,long) */ @Override public void sendMessage(Message<?> message,long timeoutMillis) { Session session; if ((session = this.session.get()) != null) { throwable.set(null); future.set(null); Async asyncRemote = session.getAsyncRemote(); asyncRemote.setSendTimeout(timeoutMillis); if (message instanceof Message.TextMessage) { Message.TextMessage text = (Message.TextMessage) message; future.set(asyncRemote.sendText(text.getPayload())); } if (message instanceof Message.BinaryMessage) { Message.BinaryMessage binary = (Message.BinaryMessage) message; future.set(asyncRemote.sendBinary(binary.getPayload())); } } }
/** * Creates two sessions one that's closed and one that's open,sends an event and makes sure * that the closed gets collected and removed and that the event only gets propagated to the * open one */ @Test public void testPublishEvent() { MessageSummary actualEvent = mock(MessageSummary.class); String eventType = actualEvent.getClass().getSimpleName(); ChatAlyticsEvent event = new ChatAlyticsEvent(DateTime.Now(),eventType,actualEvent); Async asyncRemote = mock(Async.class); when(session.getAsyncRemote()).thenReturn(asyncRemote); // open two sockets make one open and one closed ConnectionType type = ConnectionType.SUBSCRIBER; underTest.openSocket(type,session); verify(session).getId(); verify(session).setMaxIdleTimeout(0); verifyNoMoreInteractions(session); Session closedSession = mock(Session.class); when(closedSession.getId()).thenReturn("id2"); when(closedSession.isopen()).thenReturn(false); underTest.openSocket(type,closedSession); verify(closedSession).getId(); verify(closedSession).setMaxIdleTimeout(0); verifyNoMoreInteractions(closedSession); verify(session).isopen(); verifyNoMoreInteractions(session); assertEquals(2,underTest.numSessions()); underTest.publishEvent(event); verify(session,times(2)).isopen(); verify(session).getAsyncRemote(); verifyNoMoreInteractions(session); verify(asyncRemote).sendobject(event); verifyNoMoreInteractions(asyncRemote); verify(closedSession).isopen(); verifyNoMoreInteractions(closedSession); assertEquals(1,underTest.numSessions()); }
public void sendTextAsync(Session session,String text) { Async asyncRemote = session.getAsyncRemote(); if (this.asyncTimeout != null) { asyncRemote.setSendTimeout(this.asyncTimeout.longValue()); } asyncRemote.sendText(text); }
protected Session mockSession(String id,ArgumentMatcher<Message> match) { Session s = mock(Session.class); when(s.getId()).thenReturn(id); when(s.isopen()).thenReturn(true); Async mockAsync = mockAsync(match); RemoteEndpoint.Basic mockBasic = mockBasic(match); when(s.getAsyncRemote()).thenReturn(mockAsync); when(s.getBasicRemote()).thenReturn(mockBasic); return s; }
/** * Given an open and a closed session,this test makes sure that the event is only sent to the * open session. It also makes sure that the closed session gets removed from the list of open * sessions */ @Test public void testOnMessage() { // open the compute connection Session computeSession = mock(Session.class); URI computeURI = URI.create("http://fake" + RT_COmpuTE_ENDPOINT); when(computeSession.getRequestURI()).thenReturn(computeURI); underTest.onopen(computeSession); assertEquals(0,underTest.getSessions().size()); verify(computeSession).getRequestURI(); verify(computeSession).setMaxIdleTimeout(0); verifyNoMoreInteractions(computeSession); assertTrue(underTest.isConnectedToCompute()); // add two sessions,one closed and one open Async asyncRemote = mock(Async.class); // open first client session Session firstClientSession = mock(Session.class); URI resourceURI = URI.create("http://fake" + RT_EVENT_ENDPOINT); when(firstClientSession.getRequestURI()).thenReturn(resourceURI); when(firstClientSession.isopen()).thenReturn(true); when(firstClientSession.getAsyncRemote()).thenReturn(asyncRemote); underTest.onopen(firstClientSession); verify(firstClientSession).getRequestURI(); verify(firstClientSession).getId(); verify(firstClientSession).setMaxIdleTimeout(0); verifyNoMoreInteractions(firstClientSession); assertEquals(1,underTest.getSessions().size()); // open second client session Session secondClientSession = mock(Session.class); when(secondClientSession.getRequestURI()).thenReturn(resourceURI); when(secondClientSession.isopen()).thenReturn(true); when(secondClientSession.getAsyncRemote()).thenReturn(asyncRemote); underTest.onopen(secondClientSession); verify(secondClientSession).getRequestURI(); verify(secondClientSession).getId(); verify(secondClientSession).setMaxIdleTimeout(0); verifyNoMoreInteractions(secondClientSession); assertEquals(2,underTest.getSessions().size()); // close the first session when(firstClientSession.isopen()).thenReturn(false); ChatAlyticsEvent event = mock(ChatAlyticsEvent.class); underTest.onMessage(event); verify(event).setClazz(null); verify(firstClientSession,never()).getAsyncRemote(); verify(secondClientSession).getAsyncRemote(); verify(asyncRemote).sendobject(event); assertEquals(1,underTest.getSessions().size()); }
@Override public Async getAsyncRemote() { // Todo Auto-generated method stub return null; }
public Async getAsyncRemote() { // Todo Auto-generated method stub return null; }
public KafkaConsumerTask(KafkaStream stream,Async remoteEndpoint,final Session session,final boolean messagesOnly) { this.stream = stream; this.remoteEndpoint = remoteEndpoint; this.session = session; this.messagesOnly = messagesOnly; }
protected Async mockAsync(ArgumentMatcher<Message> match) { Async async = mock(Async.class); when(async.sendobject(Mockito.argThat(match))).thenReturn(null); return async; }
public static void setCom(Async com){ AbstractInterlocutor.com = com; }
public static void setCom(Async com){ Answer.com = com; }
C# WebSocket SendAsync 异常
如何解决C# WebSocket SendAsync 异常?
我正在执行一个使用 WebSocketClient 与 Java Springboot websocketserver 通信的网络核心应用程序。 我从 C# 通过 websocket 发送了超过 20000 条消息:
await client.SendAsync(new ArraySegment<byte>(bytes),WebSocketMessageType.Text,true,_cancellationToken);
但是,有时,某些消息会给出下一个例外:
The Specified argument was out of the range of valid values
堆栈跟踪:
at System.Net.WebSOckets.ManagedWebSocket.<SendFrameFallbackAsync>d_61.MoveNext()
at System.Runtime.ExceptionServices.ExceptiondispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at MyWebSocket.ClientHandler.<SendMessage>d_8.MoveNext() in C:\MyProjects\MyWebSocket\ClientHandler.cs:line 71
该行对应于上面放置的 Send async。
我已经尝试在 java 项目上增加 TextMessage 缓冲区大小,但无论字节大小如何,异常一直发生。并非所有消息都会发生这种情况,只有其中一些消息会发生这种情况。 这不会阻止 java springboot 继续接收消息并处理它们,所以我认为问题在于消息在 C# 客户端中发送的方式。
任何想法将不胜感激。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
io.netty.handler.codec.http.websocketx.PongWebSocketFrame的实例源码
private void handlerWebSocketFrame(ChannelHandlerContext ctx,WebSocketFrame frame) { // 判断是否关闭链路的指令 if (frame instanceof CloseWebSocketFrame) { socketServerHandshaker.close(ctx.channel(),(CloseWebSocketFrame) frame.retain()); } // 判断是否ping消息 if (frame instanceof PingWebSocketFrame) { ctx.channel().write( new PongWebSocketFrame(frame.content().retain())); return; } // 本例程仅支持文本消息,不支持二进制消息 if (!(frame instanceof TextWebSocketFrame)) { throw new UnsupportedOperationException(String.format( "%s frame types not supported",frame.getClass().getName())); } // 返回应答消息 String request = ((TextWebSocketFrame) frame).text(); System.out.println("服务端收到:" + request); TextWebSocketFrame tws = new TextWebSocketFrame(new Date().toString() + ctx.channel().id() + ":" + request); // 群发 group.writeAndFlush(tws); }
private void handleFrame(Channel channel,WebSocketFrame frame,WebSocketUpgradeHandler handler,NettyWebSocket webSocket) throws Exception { if (frame instanceof CloseWebSocketFrame) { Channels.setdiscard(channel); CloseWebSocketFrame closeFrame = (CloseWebSocketFrame) frame; webSocket.onClose(closeFrame.statusCode(),closeFrame.reasonText()); } else { ByteBuf buf = frame.content(); if (buf != null && buf.readableBytes() > 0) { HttpResponseBodyPart part = config.getResponseBodyPartFactory().newResponseBodyPart(buf,frame.isFinalFragment()); handler.onBodyPartReceived(part); if (frame instanceof BinaryWebSocketFrame) { webSocket.onBinaryFragment(part); } else if (frame instanceof TextWebSocketFrame) { webSocket.onTextFragment(part); } else if (frame instanceof PingWebSocketFrame) { webSocket.onPing(part); } else if (frame instanceof PongWebSocketFrame) { webSocket.onPong(part); } } } }
@Override public void onInboundNext(ChannelHandlerContext ctx,Object frame) { if (frame instanceof CloseWebSocketFrame && ((CloseWebSocketFrame) frame).isFinalFragment()) { if (log.isDebugEnabled()) { log.debug("CloseWebSocketFrame detected. Closing Websocket"); } CloseWebSocketFrame close = (CloseWebSocketFrame) frame; sendClose(new CloseWebSocketFrame(true,close.rsv(),close.content()),f -> onHandlerTerminate()); return; } if (frame instanceof PingWebSocketFrame) { ctx.writeAndFlush(new PongWebSocketFrame(((PingWebSocketFrame) frame).content())); ctx.read(); return; } super.onInboundNext(ctx,frame); }
private Message decodeWebSocketFrame(ChannelHandlerContext ctx,WebSocketFrame frame) { // Check for closing frame if (frame instanceof CloseWebSocketFrame) { handshaker.close(ctx.channel(),(CloseWebSocketFrame) frame.retain()); return null; } if (frame instanceof PingWebSocketFrame) { ctx.write(new PongWebSocketFrame(frame.content().retain())); return null; } if (frame instanceof TextWebSocketFrame) { TextWebSocketFrame textFrame = (TextWebSocketFrame) frame; return parseMessage(textFrame.content()); } if (frame instanceof BinaryWebSocketFrame) { BinaryWebSocketFrame binFrame = (BinaryWebSocketFrame) frame; return parseMessage(binFrame.content()); } log.warn("Message format error: " + frame); return null; }
private void handleWebSocketFrame(ChannelHandlerContext ctx,WebSocketFrame frame) { // Check for closing frame if (frame instanceof CloseWebSocketFrame) { handshaker.close(ctx.channel(),(CloseWebSocketFrame) frame.retain()); return; } if (frame instanceof PingWebSocketFrame) { ctx.write(new PongWebSocketFrame(frame.content().retain())); return; } if (frame instanceof TextWebSocketFrame) { // Echo the frame ctx.write(frame.retain()); return; } if (frame instanceof BinaryWebSocketFrame) { // Echo the frame ctx.write(frame.retain()); return; } }
private void handleWebSocketFrame(ChannelHandlerContext ctx,WebSocketFrame frame) { // Check for closing frame if (frame instanceof CloseWebSocketFrame) { addTraceForFrame(frame,"close"); handshaker.close(ctx.channel(),(CloseWebSocketFrame) frame.retain()); return; } if (frame instanceof PingWebSocketFrame) { addTraceForFrame(frame,"ping"); ctx.channel().write(new PongWebSocketFrame(frame.content().retain())); return; } if (!(frame instanceof TextWebSocketFrame)) { throw new UnsupportedOperationException(String.format("%s frame types not supported",frame.getClass() .getName())); } // todo [om] think about BinaryWebsocketFrame handleTextWebSocketFrameInternal((TextWebSocketFrame) frame,ctx); }
@Override protected void channelRead0(ChannelHandlerContext context,Object message) throws Exception { final Channel channel = context.channel(); if (!handshaker.isHandshakeComplete()) { handshaker.finishHandshake(channel,(FullHttpResponse) message); channel.pipeline().addBefore(HANDLER_NAME,"websocket-frame-aggregator",new WebSocketFrameAggregator(64 * 1024)); subscriber.onStart(); return; } if (message instanceof FullHttpResponse) { final FullHttpResponse response = (FullHttpResponse) message; throw new IllegalStateException( "Unexpected FullHttpResponse (getStatus=" + response.getStatus() + ",content=" + response.content().toString(CharsetUtil.UTF_8) + ')'); } final WebSocketFrame frame = (WebSocketFrame) message; if (frame instanceof PingWebSocketFrame) { context.writeAndFlush(new PongWebSocketFrame(((PingWebSocketFrame)frame).retain().content())); } else if (frame instanceof BinaryWebSocketFrame) { final ByteBufInputStream input = new ByteBufInputStream(((BinaryWebSocketFrame)message).content()); final Envelope envelope = Envelope.ADAPTER.decode(input); subscriber.onNext(envelope); } }
private void handleWebSocketFrame(ChannelHandlerContext ctx,(CloseWebSocketFrame) frame.retain()); return; } if (frame instanceof PingWebSocketFrame) { ctx.channel().write(new PongWebSocketFrame(frame.content().retain())); return; } if (!(frame instanceof TextWebSocketFrame)) { throw new UnsupportedOperationException(String.format("%s frame types not supported",frame.getClass() .getName())); } // Send the uppercase string back. String request = ((TextWebSocketFrame) frame).text(); System.err.printf("%s received %s%n",ctx.channel(),request); ctx.channel().write(new TextWebSocketFrame(request.toupperCase())); }
private void handleWebSocketFrame(ChannelHandlerContext ctx,(CloseWebSocketFrame) frame.retain()); return; } if (frame instanceof PingWebSocketFrame) { ctx.write(new PongWebSocketFrame(frame.content().retain())); return; } if (frame instanceof TextWebSocketFrame) { // Echo the frame ctx.write(frame.retain()); return; } if (frame instanceof BinaryWebSocketFrame) { // Echo the frame ctx.write(frame.retain()); return; } }
private void handleWebSocketFrame(ChannelHandlerContext ctx,WebSocketFrame frame) { if (logger.isLoggable(Level.FINE)) { logger.fine(String.format( "Channel %s received %s",ctx.channel().hashCode(),StringUtil.simpleClassName(frame))); } if (frame instanceof CloseWebSocketFrame) { handshaker.close(ctx.channel(),(CloseWebSocketFrame) frame); } else if (frame instanceof PingWebSocketFrame) { ctx.write(new PongWebSocketFrame(frame.isFinalFragment(),frame.rsv(),frame.content()),ctx.voidPromise()); } else if (frame instanceof TextWebSocketFrame) { ctx.write(frame,ctx.voidPromise()); } else if (frame instanceof BinaryWebSocketFrame) { ctx.write(frame,ctx.voidPromise()); } else if (frame instanceof ContinuationWebSocketFrame) { ctx.write(frame,ctx.voidPromise()); } else if (frame instanceof PongWebSocketFrame) { frame.release(); // Ignore } else { throw new UnsupportedOperationException(String.format("%s frame types not supported",frame.getClass() .getName())); } }
@Override public void accept(ChannelHandlerContext ctx,WebSocketFrame frame) { if (frame instanceof CloseWebSocketFrame) { handshaker.close(ctx.channel(),(CloseWebSocketFrame) frame.retain()); endpoint.releaseReferences(); endpoint.onClose(); return; } if (frame instanceof PingWebSocketFrame) { ctx.channel().write(new PongWebSocketFrame(frame.content().retain())); return; } if (frame instanceof TextWebSocketFrame) { endpoint.onMessage(((TextWebSocketFrame) frame).text()); return; } throw new UnsupportedOperationException(String.format("Unsupported websocket frame of type %s",frame.getClass().getName())); }
private void handlerWebSocketFrame(ChannelHandlerContext ctx,WebSocketFrame frame) { // 判断是否关闭链路的指令 if (frame instanceof CloseWebSocketFrame) { handshaker.close(ctx.channel(),(CloseWebSocketFrame) frame.retain()); return; } // 判断是否ping消息 if (frame instanceof PingWebSocketFrame) { ctx.channel().write(new PongWebSocketFrame(frame.content().retain())); return; } // 仅支持文本消息,不支持二进制消息 if (!(frame instanceof TextWebSocketFrame)) { ctx.close();//(String.format("%s frame types not supported",frame.getClass().getName())); return; } }
public void handle(ChannelHandlerContext ctx,(CloseWebSocketFrame) frame); onClose(ctx); return; } if (frame instanceof PingWebSocketFrame) { ctx.channel().write(new PongWebSocketFrame(frame.content())); return; } if (!(frame instanceof TextWebSocketFrame)) { throw new UnsupportedOperationException(String.format("%s frame types not supported",frame.getClass() .getName())); } String msg = ((TextWebSocketFrame) frame).text(); onMessage(ctx,msg); }
public void handleWebSocketFrame(ChannelHandlerContext ctx,WebSocketFrame frame) { // 判断是否是关闭链路的指令 if (frame instanceof CloseWebSocketFrame) { handshaker.close(ctx.channel(),(CloseWebSocketFrame) frame.retain()); return; } // 判断是否是Ping消息 if (frame instanceof PingWebSocketFrame) { ctx.channel().write(new PongWebSocketFrame(frame.content().retain())); return; } if (!(frame instanceof TextWebSocketFrame)) { throw new UnsupportedOperationException(String.format("%s frame types not supported",frame.getClass().getName())); } //返回应答消息 String request= ((TextWebSocketFrame)frame).text(); System.out.println(String.format("%s received %s",request)); ctx.channel().write(new TextWebSocketFrame(request+",现在时刻:"+new Date())); }
@Override public void channelRead(ChannelHandlerContext ctx,Object msg) throws UnkNownWebSocketFrameTypeException,ServerConnectorException { if (!(msg instanceof WebSocketFrame)) { logger.error("Expecting WebSocketFrame. UnkNown type."); throw new UnkNownWebSocketFrameTypeException("Expecting WebSocketFrame. UnkNown type."); } if (msg instanceof TextWebSocketFrame) { notifyTextMessage((TextWebSocketFrame) msg); } else if (msg instanceof BinaryWebSocketFrame) { notifyBinaryMessage((BinaryWebSocketFrame) msg); } else if (msg instanceof CloseWebSocketFrame) { notifyCloseMessage((CloseWebSocketFrame) msg); } else if (msg instanceof PingWebSocketFrame) { notifyPingMessage((PingWebSocketFrame) msg); } else if (msg instanceof PongWebSocketFrame) { notifyPongMessage((PongWebSocketFrame) msg); } }
private void handleWebSocketFrame(ChannelHandlerContext ctx,frame.getClass() .getName())); } }
private void handleWebSocketFrame(ChannelHandlerContext ctx,frame.getClass() .getName())); } // Send the uppercase string back. String request = ((TextWebSocketFrame) frame).text(); if (logger.isLoggable(Level.FINE)) { logger.fine(String.format("%s received %s",request)); } ctx.channel().write(new TextWebSocketFrame(request.toupperCase())); }
private void handleWebSocketFrame(ChannelHandlerContext ctx,request)); } ctx.channel().write(new TextWebSocketFrame(request.toupperCase())); }
@Override protected void channelRead0(ChannelHandlerContext ctx,WebSocketFrame frame) throws Exception { this.last = ctx; if (frame instanceof CloseWebSocketFrame) { this.log.debug("recevied close frame"); this.server.unsubscribe(this); this.handshaker.close(ctx.channel(),(CloseWebSocketFrame)frame); } else if (frame instanceof PingWebSocketFrame) { this.log.debug("recevied ping frame"); ctx.write(new PongWebSocketFrame(frame.content())); } else if (frame instanceof TextWebSocketFrame) { this.log.debug("recevied text frame"); this.handleTextWebSocketFrame(ctx,(TextWebSocketFrame)frame); } else { this.log.info("recevied unkNown incompatible frame"); ctx.close(); } }
private void handleWebSocketFrame(ChannelHandlerContext ctx,WebSocketFrame frame) { _logger.debug("Handling websocket frame"); // Check for closing frame if (frame instanceof CloseWebSocketFrame) { _handshaker.close(ctx.channel(),(CloseWebSocketFrame) frame.retain()); return; } if (frame instanceof PingWebSocketFrame) { ctx.channel().write(new PongWebSocketFrame(frame.content().retain())); return; } if (!(frame instanceof TextWebSocketFrame)) { throw new UnsupportedOperationException(String.format("%s frame types not supported",frame.getClass() .getName())); } String request = ((TextWebSocketFrame) frame).text(); _logger.debug("{} received {}",request); _messageQueue.add(frame.content().retain()); //ctx.channel().write(new TextWebSocketFrame(request.toupperCase())); }
private void handleWebSocketFrame(ChannelHandlerContext ctx,request)); } ctx.channel().write(new TextWebSocketFrame(request.toupperCase())); }
private void handleWebSocketFrame(ChannelHandlerContext ctx,request)); } ctx.channel().write(new TextWebSocketFrame(request.toupperCase())); }
private void handleWebSocketFrame(ChannelHandlerContext ctx,frame.content())); } else if (frame instanceof TextWebSocketFrame) { ctx.write(frame); } else if (frame instanceof BinaryWebSocketFrame) { ctx.write(frame); } else if (frame instanceof ContinuationWebSocketFrame) { ctx.write(frame); } else if (frame instanceof PongWebSocketFrame) { frame.release(); // Ignore } else { throw new UnsupportedOperationException(String.format("%s frame types not supported",frame.getClass() .getName())); } }
private void handleWebSocketFrame(ChannelHandlerContext ctx,WebSocketFrame frame) { // Check for closing frame if (frame instanceof CloseWebSocketFrame) { handshaker.close(ctx.channel(),(CloseWebSocketFrame) frame.retain()); return; } if (frame instanceof PingWebSocketFrame) { ctx.write(new PongWebSocketFrame(frame.content().retain())); return; } if (frame instanceof TextWebSocketFrame) { // Echo the frame ctx.write(frame.retain()); return; } if (frame instanceof BinaryWebSocketFrame) { // Echo the frame ctx.write(frame.retain()); } }
private void handleWebSocketFrame(ChannelHandlerContext ctx,(CloseWebSocketFrame) frame.retain()); return; } if (frame instanceof PingWebSocketFrame) { ctx.channel().write(new PongWebSocketFrame(frame.content().retain())); return; } if (frame instanceof BinaryWebSocketFrame) try { this.connection.onMessage(((BinaryWebSocketFrame) frame).content().retain()); } catch (Exception e) { logger.error("onMessage error",e); handshaker.close(ctx.channel(),new CloseWebSocketFrame(true,frame.content().clear() .writeShort(1000) .writeBytes(e.getMessage().getBytes(CharsetUtil.UTF_8)) .retain())); } }
private void handleWebSocketFrame(ChannelHandlerContext ctx,WebSocketFrame msg) throws Exception { if (log.isDebugEnabled()) log.debug("Received {} WebSocketFrame: {} from channel: {}",getTransportType().getName(),msg,ctx.channel()); if (msg instanceof CloseWebSocketFrame) { sessionIdByChannel.remove(ctx.channel()); ChannelFuture f = ctx.writeAndFlush(msg); f.addListener(ChannelFutureListener.CLOSE); } else if (msg instanceof PingWebSocketFrame) { ctx.writeAndFlush(new PongWebSocketFrame(msg.content())); } else if (msg instanceof TextWebSocketFrame || msg instanceof BinaryWebSocketFrame){ Packet packet = PacketDecoder.decodePacket(msg.content()); packet.setTransportType(getTransportType()); String sessionId = sessionIdByChannel.get(ctx.channel()); packet.setSessionId(sessionId); msg.release(); ctx.fireChannelRead(packet); } else { msg.release(); log.warn("{} frame type is not supported",msg.getClass().getName()); } }
@Override protected void channelRead0(ChannelHandlerContext ctx,Object msg) throws Exception { LOG.info("Received msg: {}",msg); if (!this.handshaker.isHandshakeComplete()) { this.handshaker.finishHandshake(ctx.channel(),(FullHttpResponse) msg); LOG.info("Client connected."); this.connected = true; this.handshakeFuture.setSuccess(); return; } if (msg instanceof FullHttpResponse) { throw new IllegalStateException("Unexpected response: " + msg.toString()); } WebSocketFrame frame = (WebSocketFrame) msg; if (frame instanceof TextWebSocketFrame) { synchronized (responses) { responses.add(((TextWebSocketFrame) frame).text().getBytes(StandardCharsets.UTF_8)); } } else if (frame instanceof BinaryWebSocketFrame) { ByteBuf buf = frame.content(); byte[] b = new byte[buf.readableBytes()]; buf.readBytes(b); synchronized (responses) { responses.add(b); } } else if (frame instanceof PingWebSocketFrame) { LOG.info("Returning pong message"); ctx.writeAndFlush(new PongWebSocketFrame()); } else if (frame instanceof CloseWebSocketFrame) { LOG.info("Received message from server to close the channel."); ctx.close(); } else { LOG.warn("Unhandled frame type received: " + frame.getClass()); } }
@Override protected void channelRead0(ChannelHandlerContext ctx,Object msg) throws Exception { Channel ch = ctx.channel(); if (!handshaker.isHandshakeComplete()) { handshaker.finishHandshake(ch,(FullHttpResponse) msg); System.out.println("WebSocket Client connected!"); handshakeFuture.setSuccess(); return; } if (msg instanceof FullHttpResponse) { FullHttpResponse response = (FullHttpResponse) msg; throw new IllegalStateException( "Unexpected FullHttpResponse (getStatus=" + response.getStatus() + ",content=" + response.content().toString(CharsetUtil.UTF_8) + ')'); } else if (msg instanceof WebSocketFrame) { WebSocketFrame frame = (WebSocketFrame) msg; if (msg instanceof TextWebSocketFrame) { TextWebSocketFrame textFrame = (TextWebSocketFrame) frame; System.out.println("WebSocket Client received message: " + textFrame.text()); } else if (msg instanceof PongWebSocketFrame) { System.out.println("WebSocket Client received pong"); } else if (msg instanceof CloseWebSocketFrame) { System.out.println("WebSocket Client received closing"); ch.close(); } } }
@Override protected void channelRead0(ChannelHandlerContext ctx,(FullHttpResponse) msg); LOG.info("Client connected."); this.connected = true; this.handshakeFuture.setSuccess(); return; } if (msg instanceof FullHttpResponse) { throw new IllegalStateException("Unexpected response: " + msg.toString()); } WebSocketFrame frame = (WebSocketFrame) msg; if (frame instanceof TextWebSocketFrame) { synchronized (responses) { responses.add(((TextWebSocketFrame) frame).text()); } } else if (frame instanceof PingWebSocketFrame) { LOG.info("Returning pong message"); ctx.writeAndFlush(new PongWebSocketFrame()); } else if (frame instanceof CloseWebSocketFrame) { LOG.info("Received message from server to close the channel."); ctx.close(); } else { LOG.warn("Unhandled frame type received: " + frame.getClass()); } }
@Override protected void channelRead0(final ChannelHandlerContext ctx,final Object msg) throws Exception { final Channel ch = ctx.channel(); if (!handshaker.isHandshakeComplete()) { // web socket client connected handshaker.finishHandshake(ch,(FullHttpResponse) msg); handshakeFuture.setSuccess(); return; } if (msg instanceof FullHttpResponse) { final FullHttpResponse response = (FullHttpResponse) msg; throw new Exception("Unexpected FullHttpResponse (getStatus=" + response.getStatus() + ",content=" + response.content().toString(CharsetUtil.UTF_8) + ')'); } // a close frame doesn't mean much here. errors raised from closed channels will mark the host as dead final WebSocketFrame frame = (WebSocketFrame) msg; if (frame instanceof TextWebSocketFrame) { ctx.fireChannelRead(frame.retain(2)); } else if (frame instanceof PongWebSocketFrame) { } else if (frame instanceof BinaryWebSocketFrame) { ctx.fireChannelRead(frame.retain(2)); } else if (frame instanceof CloseWebSocketFrame) ch.close(); }
@Override public void channelRead0(ChannelHandlerContext ctx,Object msg) throws Exception { Channel ch = ctx.channel(); if (!handshaker.isHandshakeComplete()) { handshaker.finishHandshake(ch,(FullHttpResponse) msg); handshakeFuture.setSuccess(); //connection is opened. client.onopen(handshaker); return; } if (msg instanceof FullHttpResponse) { FullHttpResponse response = (FullHttpResponse) msg; throw new IllegalStateException( "Unexpected FullHttpResponse (getStatus=" + response.status() + ",content=" + response.content().toString(CharsetUtil.UTF_8) + ')'); } WebSocketFrame frame = (WebSocketFrame) msg; if (frame instanceof TextWebSocketFrame) { TextWebSocketFrame textFrame = (TextWebSocketFrame) frame; client.onMessage(textFrame.text()); } else if (frame instanceof PongWebSocketFrame) { /* * placeholder. maybe add onPong method to the RhinoClient */ } else if (frame instanceof CloseWebSocketFrame) { client.onClose(); ch.close(); } }
@Override public void channelRead0(ChannelHandlerContext ctx,Object msg) throws Exception { Channel ch = ctx.channel(); if (!handshaker.isHandshakeComplete()) { handshaker.finishHandshake(ch,(FullHttpResponse) msg); System.out.println("WebSocket Client connected!"); handshakeFuture.setSuccess(); return; } if (msg instanceof FullHttpResponse) { FullHttpResponse response = (FullHttpResponse) msg; throw new IllegalStateException( "Unexpected FullHttpResponse (getStatus=" + response.status() + ",content=" + response.content().toString(CharsetUtil.UTF_8) + ')'); } WebSocketFrame frame = (WebSocketFrame) msg; if (frame instanceof TextWebSocketFrame) { TextWebSocketFrame textFrame = (TextWebSocketFrame) frame; System.out.println("WebSocket Client received message: " + textFrame.text()); } else if (frame instanceof PongWebSocketFrame) { System.out.println("WebSocket Client received pong"); } else if (frame instanceof CloseWebSocketFrame) { System.out.println("WebSocket Client received closing"); ch.close(); } }
protected void handleWebSocketFrame(ChannelHandlerContext ctx,WebSocketFrame frame) { logger.debug("Received incoming frame [{}]",frame.getClass().getName()); // Check for closing frame if (frame instanceof CloseWebSocketFrame) { if (frameBuffer != null) { handleMessageCompleted(ctx,frameBuffer.toString()); } handshaker.close(ctx.channel(),(CloseWebSocketFrame) frame.retain()); return; } if (frame instanceof PingWebSocketFrame) { ctx.channel().writeAndFlush(new PongWebSocketFrame(frame.content().retain())); return; } if (frame instanceof PongWebSocketFrame) { logger.info("Pong frame received"); return; } if (frame instanceof TextWebSocketFrame) { frameBuffer = new StringBuilder(); frameBuffer.append(((TextWebSocketFrame)frame).text()); } else if (frame instanceof ContinuationWebSocketFrame) { if (frameBuffer != null) { frameBuffer.append(((ContinuationWebSocketFrame)frame).text()); } else { logger.warn("Continuation frame received without initial frame."); } } else { throw new UnsupportedOperationException(String.format("%s frame types not supported",frame.getClass().getName())); } // Check if Text or Continuation Frame is final fragment and handle if needed. if (frame.isFinalFragment()) { handleMessageCompleted(ctx,frameBuffer.toString()); frameBuffer = null; } }
private void handleWebSocketFrame(ChannelHandlerContext ctx,WebSocketFrame frame) { // 判断是否是关闭链路的指令 if (frame instanceof CloseWebSocketFrame) { handshaker.close(ctx.channel(),(CloseWebSocketFrame) frame.retain()); return; } // 判断是否是Ping消息 if (frame instanceof PingWebSocketFrame) { ctx.channel().write( new PongWebSocketFrame(frame.content().retain())); return; } // 本例程仅支持文本消息,不支持二进制消息 if (!(frame instanceof TextWebSocketFrame)) { throw new UnsupportedOperationException(String.format( "%s frame types not supported",frame.getClass().getName())); } // 返回应答消息 String request = ((TextWebSocketFrame) frame).text(); if (logger.isLoggable(Level.FINE)) { logger.fine(String.format("%s received %s",request)); } ctx.channel().write( new TextWebSocketFrame(request + ",欢迎使用Netty WebSocket服务,现在时刻:" + new java.util.Date().toString())); }
@Override public void channelRead0(ChannelHandlerContext ctx,(FullHttpResponse) msg); System.out.println("WebSocket Client connected!"); handshakeFuture.setSuccess(); return; } if (msg instanceof FullHttpResponse) { FullHttpResponse response = (FullHttpResponse) msg; throw new IllegalStateException( "Unexpected FullHttpResponse (getStatus=" + response.getStatus() + ",content=" + response.content().toString(CharsetUtil.UTF_8) + ')'); } WebSocketFrame frame = (WebSocketFrame) msg; if (frame instanceof TextWebSocketFrame) { TextWebSocketFrame textFrame = (TextWebSocketFrame) frame; System.out.println("WebSocket Client received message: " + textFrame.text()); } else if (frame instanceof PongWebSocketFrame) { System.out.println("WebSocket Client received pong"); } else if (frame instanceof CloseWebSocketFrame) { System.out.println("WebSocket Client received closing"); ch.close(); } }
@Override public void channelRead0(ChannelHandlerContext ctx,(FullHttpResponse) msg); logger.debug("WebSocket Client connected!"); handshakeFuture.setSuccess(); return; } if (msg instanceof FullHttpResponse) { FullHttpResponse response = (FullHttpResponse) msg; throw new IllegalStateException( "Unexpected FullHttpResponse (getStatus=" + response.status() + ",content=" + response.content().toString(CharsetUtil.UTF_8) + ')'); } WebSocketFrame frame = (WebSocketFrame) msg; if (frame instanceof TextWebSocketFrame) { TextWebSocketFrame textFrame = (TextWebSocketFrame) frame; logger.debug("WebSocket Client received text message: " + textFrame.text()); textReceived = textFrame.text(); } else if (frame instanceof BinaryWebSocketFrame) { BinaryWebSocketFrame binaryFrame = (BinaryWebSocketFrame) frame; bufferReceived = binaryFrame.content().nioBuffer(); logger.debug("WebSocket Client received binary message: " + bufferReceived.toString()); } else if (frame instanceof PongWebSocketFrame) { logger.debug("WebSocket Client received pong"); PongWebSocketFrame pongFrame = (PongWebSocketFrame) frame; bufferReceived = pongFrame.content().nioBuffer(); } else if (frame instanceof CloseWebSocketFrame) { logger.debug("WebSocket Client received closing"); ch.close(); } }
private void notifyPongMessage(PongWebSocketFrame pongWebSocketFrame) throws ServerConnectorException { //Control message for WebSocket is Pong Message ByteBuf byteBuf = pongWebSocketFrame.content(); ByteBuffer byteBuffer = byteBuf.nioBuffer(); WebSocketMessageImpl webSocketControlMessage = new WebSocketControlMessageImpl(WebSocketControlSignal.PONG,byteBuffer); webSocketControlMessage = setupCommonProperties(webSocketControlMessage); connectorFuture.notifyWSListener((WebSocketControlMessage) webSocketControlMessage); }
@Override public void channelRead0(ChannelHandlerContext ctx,URISyntaxException,ServerConnectorException { Channel ch = ctx.channel(); if (!handshaker.isHandshakeComplete()) { handshaker.finishHandshake(ch,(FullHttpResponse) msg); log.debug("WebSocket Client connected!"); handshakeFuture.setSuccess(); channelSession = WebSocketUtil.getSession(ctx,isSecure,requestedUri); return; } if (msg instanceof FullHttpResponse) { FullHttpResponse response = (FullHttpResponse) msg; throw new IllegalStateException( "Unexpected FullHttpResponse (getStatus=" + response.status() + ",content=" + response.content().toString(CharsetUtil.UTF_8) + ')'); } WebSocketFrame frame = (WebSocketFrame) msg; if (frame instanceof TextWebSocketFrame) { notifyTextMessage((TextWebSocketFrame) frame,ctx); } else if (frame instanceof BinaryWebSocketFrame) { notifyBinaryMessage((BinaryWebSocketFrame) frame,ctx); } else if (frame instanceof PongWebSocketFrame) { notifyPongMessage((PongWebSocketFrame) frame,ctx); } else if (frame instanceof PingWebSocketFrame) { notifyPingMessage((PingWebSocketFrame) frame,ctx); } else if (frame instanceof CloseWebSocketFrame) { if (channelSession != null) { channelSession.setIsOpen(false); } notifyCloseMessage((CloseWebSocketFrame) frame,ctx); ch.close(); } else { throw new UnkNownWebSocketFrameTypeException("Cannot identify the WebSocket frame type"); } }
private void notifyPongMessage(PongWebSocketFrame pongWebSocketFrame,ChannelHandlerContext ctx) throws ServerConnectorException { //Control message for WebSocket is Pong Message ByteBuf byteBuf = pongWebSocketFrame.content(); ByteBuffer byteBuffer = byteBuf.nioBuffer(); WebSocketMessageImpl webSocketControlMessage = new WebSocketControlMessageImpl(WebSocketControlSignal.PONG,byteBuffer); webSocketControlMessage = setupCommonProperties(webSocketControlMessage,ctx); connectorListener.onMessage((WebSocketControlMessage) webSocketControlMessage); }
private boolean handleWebSocketFrame(ChannelHandlerContext ctx,WebSocketFrame frame) { // Check for closing frame if (frame instanceof CloseWebSocketFrame) { this.handshaker.close(ctx.channel(),((CloseWebSocketFrame) frame).retain()); return false; } else if (frame instanceof PingWebSocketFrame) { ctx.writeAndFlush(new PongWebSocketFrame(frame.content().retain())); return false; } else if (!(frame instanceof TextWebSocketFrame) && !(frame instanceof BinaryWebSocketFrame)) { throw new UnsupportedOperationException(String.format("%s frame types not supported",frame.getClass().getName())); } return true; }
io.netty.handler.codec.http.websocketx.WebSocketClientHandshaker的实例源码
@Override protected void initChannel(SocketChannel channel) throws SSLException { URI uri = config.getConnectionWebsocketUri(); DefaultHttpHeaders headers = new DefaultHttpHeaders(); headers.add(USER_ID_HEADER,config.getConnectionUserId().toString()); headers.add(USER_PASSWORD_HEADER,config.getConnectionUserPassword()); headers.add(supplier_ID_HEADER,config.getConnectionServerId()); WebSocketClientHandshaker handshaker = WebSocketClientHandshakerFactory.newHandshaker(uri,WS_VERSION,null,false,headers); ChannelPipeline pipeline = channel.pipeline(); if (config.isConnectionSecure()) { try { SslContext sslContext = SslContext.newClientContext(InsecureTrustManagerFactory.INSTANCE); pipeline.addLast(sslContext.newHandler(channel.alloc())); } catch (SSLException e) { logger.log(Level.SEVERE,"Shutting down client due to unexpected failure to create SSL context",e); throw e; } } pipeline.addLast(new HttpClientCodec()); pipeline.addLast(new HttpObjectAggregator(8192)); pipeline.addLast(new AudioConnectClientHandler(handshaker)); }
@Before public void setup() throws Exception { s = new Server(conf); s.run(); Connector con = mac.getConnector("root","secret"); con.securityOperations().changeUserAuthorizations("root",new Authorizations("A","B","C","D","E","F")); this.sessionId = UUID.randomUUID().toString(); AuthCache.getCache().put(sessionId,token); group = new NioEventLoopGroup(); SslContext ssl = SslContextBuilder.forClient().trustManager(InsecureTrustManagerFactory.INSTANCE).build(); String cookieVal = ClientCookieEncoder.STRICT.encode(Constants.COOKIE_NAME,sessionId); HttpHeaders headers = new DefaultHttpHeaders(); headers.add(Names.COOKIE,cookieVal); WebSocketClientHandshaker handshaker = WebSocketClientHandshakerFactory.newHandshaker(LOCATION,WebSocketVersion.V13,(String) null,headers); handler = new ClientHandler(handshaker); Bootstrap boot = new Bootstrap(); boot.group(group).channel(NioSocketChannel.class).handler(new ChannelInitializer<SocketChannel>() { @Override protected void initChannel(SocketChannel ch) throws Exception { ch.pipeline().addLast("ssl",ssl.newHandler(ch.alloc(),"127.0.0.1",WS_PORT)); ch.pipeline().addLast(new HttpClientCodec()); ch.pipeline().addLast(new HttpObjectAggregator(8192)); ch.pipeline().addLast(handler); } }); ch = boot.connect("127.0.0.1",WS_PORT).sync().channel(); // Wait until handshake is complete while (!handshaker.isHandshakeComplete()) { sleepUninterruptibly(500,TimeUnit.MILLISECONDS); LOG.debug("Waiting for Handshake to complete"); } }
@Before public void setup() throws Exception { s = new Server(conf); s.run(); Connector con = mac.getConnector("root",TimeUnit.MILLISECONDS); LOG.debug("Waiting for Handshake to complete"); } }
public WebSocketTargetHandler(WebSocketClientHandshaker handshaker,boolean isSecure,String requestedUri,String target,WebSocketConnectorListener webSocketConnectorListener) { this.handshaker = handshaker; this.isSecure = isSecure; this.requestedUri = requestedUri; this.target = target; this.connectorListener = webSocketConnectorListener; handshakeFuture = null; }
@Override public void addToPipeline(final ChannelPipeline pipeline) { pipeline.addLast("http-codec",new HttpClientCodec()); pipeline.addLast("aggregator",new HttpObjectAggregator(8192)); final WebSocketClientHandshaker handShaker = new WhiteSpaceInPathWebSocketClientHandshaker13(serverUri,PROTOCOL,createHttpHeaders(httpHeaders),Integer.MAX_VALUE); pipeline.addLast("websocket-protocol-handler",new WebSocketClientProtocolHandler(handShaker)); pipeline.addLast("websocket-frame-codec",new ByteBufToWebSocketFrameCodec()); }
public WebSocketClientHandler(long uid,WebSocketClientHandshaker handshaker) { this.uid = uid; this.handshaker = handshaker; }
public ClientHandler(WebSocketClientHandshaker handshaker) { this.handshaker = handshaker; }
private AudioConnectClientHandler(WebSocketClientHandshaker handshaker) { this.handshaker = handshaker; }
public ClientHandler(WebSocketClientHandshaker handshaker) { this.handshaker = handshaker; }
MeetupWebSocketClientHandler(WebSocketClientHandshaker handshaker,RSVPProducer rsvpProducer) { this.handshaker = handshaker; this.rsvpProducer = rsvpProducer; }
public WebSocketClientHandler(final WebSocketClientHandshaker handshaker) { this.handshaker = handshaker; }
public WebSocketClientHandler(WebSocketClientHandshaker handshaker,CountDownLatch latch) { this.handshaker = handshaker; this.latch = latch; this.isOpen = true; }
@Override public void onopen(WebSocketClientHandshaker handShaker) { // Todo Auto-generated method stub }
@Override public void onopen(WebSocketClientHandshaker handShaker) { logger.log(Level.INFO,"onopen"); }
public WebSocketClientHandler(WebSocketClientHandshaker handshaker) { this.handshaker = handshaker; }
public WebSocketClientHandler(WebSocketClientHandshaker handshaker) { this.handshaker = handshaker; }
public MessageReceiverWebSocketClientHandler(WebSocketClientHandshaker handshaker) { this.handshaker = handshaker; }
public MessageSenderWebSocketClientHandler(WebSocketClientHandshaker handshaker,String id) { this.handshaker = handshaker; publisherId = id; }
public WebSocketClientHandlerControl(WebSocketClientHandshaker handshaker) { this.handshaker = handshaker; }
public WebSocketClientHandler(WebSocketClientHandshaker handshaker) { this.handshaker = handshaker; }
public WebSocketClientHandler(WebSocketClientHandshaker handshaker) { this.handshaker = handshaker; }
public WebSocketClientHandler(WebSocketClientHandshaker handshaker) { mHandshaker = handshaker; }
public WebSocketClientHandler(WebSocketClientHandshaker handshaker) { this.handshaker = handshaker; }
@Override public void connect(WsClient client) { if (client == null) { throw new NullPointerException("client"); } final URLInfo url = client.getUrl(); String full = url.protocol + "://" + url.host + ":" + url.port + url.path; URI uri; try { uri = new URI(full); } catch (URISyntaxException e) { throw new RuntimeException(e); } WebSocketVersion v = WebSocketVersion.V13; HttpHeaders h = new DefaultHttpHeaders(); final WebSocketClientHandshaker wsch = WebSocketClientHandshakerFactory .newHandshaker(uri,v,true,h,Integer.MAX_VALUE); final WebSocketHandler handler = new WebSocketHandler(wsch,client); Bootstrap b = new Bootstrap(); b.group(Sharedobjects.getLoop()); b.channel(NioSocketChannel.class); b.handler(new ChannelInitializer<SocketChannel>() { @Override protected void initChannel(SocketChannel ch) throws Exception { ChannelPipeline p = ch.pipeline(); if (url.secure) { TrustManagerFactory man = InsecureTrustManagerFactory.INSTANCE; SslContext con = SslContext.newClientContext(man); p.addLast(con.newHandler(ch.alloc())); } p.addLast(new HttpClientCodec()); p.addLast(new HttpObjectAggregator(8192)); p.addLast(handler); } }); ChannelFuture fut = b.connect(url.host,url.port); fut.syncUninterruptibly(); handler.handshakeFuture().syncUninterruptibly(); }
public WebSocketHandler(WebSocketClientHandshaker handshake,WsClient client) { this.handshake = handshake; this.client = client; }
@Override public void connect(String url) throws Exception { URI uri = new URI(url); setConnected(false); String scheme = uri.getScheme() == null ? "http" : uri.getScheme(); final String host = uri.getHost() == null ? "127.0.0.1" : uri.getHost(); final int port; if (uri.getPort() == -1) { if ("http".equalsIgnoreCase(scheme)) { port = 80; } else if ("https".equalsIgnoreCase(scheme)) { port = 443; } else { port = -1; } } else { port = uri.getPort(); } if (!"ws".equalsIgnoreCase(scheme) && !"wss".equalsIgnoreCase(scheme)) { Notifications.Bus.notify( new Notification( "Websocket Client","Unable to connect","Only WS(S) is supported.",NotificationType.ERROR) ); return; } EventLoopGroup group = new NioEventLoopGroup(); try { WebSocketClientHandshaker handshaker = WebSocketClientHandshakerFactory.newHandshaker( uri,new DefaultHttpHeaders()); WebSocketClientHandler webSocketClientHandler = new WebSocketClientHandler(handshaker); Bootstrap bootstrap = new Bootstrap(); bootstrap.group(group) .channel(NioSocketChannel.class) .handler(new ChannelInitializer<SocketChannel>() { @Override protected void initChannel(SocketChannel ch) { ChannelPipeline p = ch.pipeline(); p.addLast( new HttpClientCodec(),new HttpObjectAggregator(8192),webSocketClientHandler); } }); channel = bootstrap.connect(uri.getHost(),port).sync().channel(); webSocketClientHandler.handshakeFuture().sync(); setConnected(true); for (; ; ); } finally { group.shutdownGracefully(); setConnected(false); } }
public WebSocketClientHandler(WebSocketClientHandshaker handshaker) { this.handshaker = handshaker; this.eventBus = EventBusService.getInstance(); }
public WebSocketClientHandler(WebSocketClientHandshaker handshaker,CountDownLatch latch) { this.handshaker = handshaker; this.latch = latch; this.isOpen = true; }
public WebSocketClientHandler(WebSocketClientHandshaker handshaker) { this.handshaker = handshaker; }
public WebSocketClientHandler(final WebSocketClientHandshaker handshaker) { this.handshaker = handshaker; }
public WebSocketClientHandler(WebSocketClientHandshaker handshaker) { this.handshaker = handshaker; }
public AbstractJsonRpcWebSocketClientHandler(WebSocketClientHandshaker handshaker) { this.handshaker = handshaker; }
public JsonRpcWebSocketClientHandler(WebSocketClientHandshaker handshaker) { super(handshaker); }
public WebsocketProtostuffEncoder(WebSocketClientHandshaker handShaker) { this.handShaker = handShaker; }
public WebSocketClientHandshaker getHandShaker() { return handShaker; }
public WebsocketProtostuffDecoder(WebSocketClientHandshaker handShaker) { super(handShaker); this.handShaker = handShaker; }
public C5ConnectionInitializer(WebSocketClientHandshaker handShaker) { super(); this.handShaker = handShaker; }
public WebSocketClientHandler(WebSocketClientHandshaker handshaker) { this.handshaker = handshaker; }
Java WebSockets: The remote endpoint was in state [TEXT_FULL_WRITING]
java Websocket 多线程向同一个session写数据,容器为tomcat
目前发现的问题是tomcat的一个bug,解决方案是:
public void sendMessage(String message) throws IOException {
synchronized(this.session) {
this.session.getBasicRemote().sendText(message);
}
//this.session.getAsyncRemote().sendText(message);
}
使用synchronized和getBasicRemote,使用getAsyncRemote的话也会报错
https://stackoverflow.com/questions/22257079/java-websockets-the-remote-endpoint-was-in-state-text-full-writing
https://bz.apache.org/bugzilla/show_bug.cgi?id=56026
https://www.cnblogs.com/interdrp/p/4866129.html
http://blog.csdn.net/luoruixiaohai/article/details/50960319
https://stackoverflow.com/questions/33381420/tomcat-throws-the-remote-endpoint-was-in-state-binary-full-writing-when
今天关于javax.websocket.RemoteEndpoint.Async的实例源码和java socket源码的介绍到此结束,谢谢您的阅读,有关C# WebSocket SendAsync 异常、io.netty.handler.codec.http.websocketx.PongWebSocketFrame的实例源码、io.netty.handler.codec.http.websocketx.WebSocketClientHandshaker的实例源码、Java WebSockets: The remote endpoint was in state [TEXT_FULL_WRITING]等更多相关知识的信息可以在本站进行查询。
本文标签: