0
我,從我的WebSocket客戶採取下面的代碼片段:的Java客戶端的WebSockets暗流的BasicWebSocketSessionRemoteEndpoint sendBinary拋出BufferOverflowException
byte[] message = "test".getBytes();
session.getBasicRemote().sendBinary(ByteBuffer.wrap(message));
會話UndertowSession和getBasicRemote()返回BasicWebSocketSessionRemoteEndpoint對象。
當調用sendBinary()方法拋出BufferOverflowException以下堆棧跟蹤:
java.nio.BufferOverflowException
at java.nio.Buffer.nextPutIndex(Buffer.java:521)
at java.nio.DirectByteBuffer.put(DirectByteBuffer.java:297)
at io.undertow.websockets.core.protocol.version07.WebSocket07FrameSinkChannel.createFrameHeader(WebSocket07FrameSinkChannel.java:129)
at io.undertow.server.protocol.framed.AbstractFramedStreamSinkChannel.getFrameHeader(AbstractFramedStreamSinkChannel.java:143)
at io.undertow.server.protocol.framed.AbstractFramedChannel.flushSenders(AbstractFramedChannel.java:623)
at io.undertow.server.protocol.framed.AbstractFramedChannel.flush(AbstractFramedChannel.java:715)
at io.undertow.server.protocol.framed.AbstractFramedChannel.queueFrame(AbstractFramedChannel.java:708)
at io.undertow.server.protocol.framed.AbstractFramedStreamSinkChannel.queueFinalFrame(AbstractFramedStreamSinkChannel.java:257)
at io.undertow.server.protocol.framed.AbstractFramedStreamSinkChannel.shutdownWrites(AbstractFramedStreamSinkChannel.java:242)
at io.undertow.websockets.core.WebSockets.sendBlockingInternal(WebSockets.java:468)
at io.undertow.websockets.core.WebSockets.sendBinaryBlocking(WebSockets.java:288)
at io.undertow.websockets.jsr.WebSocketSessionRemoteEndpoint$BasicWebSocketSessionRemoteEndpoint.sendBinary(WebSocketSessionRemoteEndpoint.java:267)
at myproject.core.server.utils.websocket.messagehandler.EchoStreamMessageHandler.onMessage(EchoStreamMessageHandler.java:49)
at myproject.core.server.utils.websocket.messagehandler.EchoStreamMessageHandler.onMessage(EchoStreamMessageHandler.java:12)
at io.undertow.websockets.jsr.FrameHandler$6.run(FrameHandler.java:248)
at io.undertow.websockets.jsr.ServerWebSocketContainer.invokeEndpointMethod(ServerWebSocketContainer.java:553)
at io.undertow.websockets.jsr.ServerWebSocketContainer.invokeEndpointMethod(ServerWebSocketContainer.java:542)
at io.undertow.websockets.jsr.FrameHandler.invokeBinaryHandler(FrameHandler.java:216)
at io.undertow.websockets.jsr.FrameHandler.onFullBinaryMessage(FrameHandler.java:329)
at io.undertow.websockets.core.AbstractReceiveListener$1.complete(AbstractReceiveListener.java:130)
at io.undertow.websockets.core.AbstractReceiveListener$1.complete(AbstractReceiveListener.java:124)
at io.undertow.websockets.core.BufferedBinaryMessage$1.handleEvent(BufferedBinaryMessage.java:113)
at io.undertow.websockets.core.BufferedBinaryMessage$1.handleEvent(BufferedBinaryMessage.java:98)
at org.xnio.ChannelListeners.invokeChannelListener(ChannelListeners.java:92)
at io.undertow.server.protocol.framed.AbstractFramedStreamSourceChannel$1.run(AbstractFramedStreamSourceChannel.java:273)
at io.undertow.server.protocol.framed.AbstractFramedChannel$3.run(AbstractFramedChannel.java:232)
at org.xnio.nio.WorkerThread.safeRun(WorkerThread.java:580)
at org.xnio.nio.WorkerThread.run(WorkerThread.java:464)
我也試着撥打sendBinary與分配的ByteBuffer:
ByteBuffer buff = ByteBuffer.allocate(message.length);
buff.put(message);
buff.flip();
this.session.getBasicRemote().sendBinary(buff);
但得到了同樣的異常。
任何想法如何解決這個問題?
謝謝!
伊利達