On 27/10/2015 19:15, Farzad Panahi wrote:
> Hi,
> 
> I am using tomcat 8.0.23 to terminate my websocket connections. I have
> the following code to take care of the incoming messages:
> 
> @OnMessage
> public void onMsg(Session session, byte[] request) {
>         executorService.execute(() ->
>                 session.getAsyncRemote().sendBinary(
>                         ByteBuffer.wrap(getResponse(session,
> request)), result -> {
>                             if (!result.isOK()) {
>                                 LOGGER.catching(result.getException());
>                             }
>                         }
>                 ));
> }
> 
> But I get the following exception:
> 
> Exception in thread "pool-6-thread-10160"
> java.lang.IllegalStateException: The remote endpoint was in state
> [BINARY_FULL_WRITING] which is an invalid state for called method
>     at 
> org.apache.tomcat.websocket.WsRemoteEndpointImplBase$StateMachine.checkState(WsRemoteEndpointImplBase.java:1148)
>     at 
> org.apache.tomcat.websocket.WsRemoteEndpointImplBase$StateMachine.binaryStart(WsRemoteEndpointImplBase.java:1101)
>     at 
> org.apache.tomcat.websocket.WsRemoteEndpointImplBase.sendBytesByCompletion(WsRemoteEndpointImplBase.java:152)
>     at 
> org.apache.tomcat.websocket.WsRemoteEndpointAsync.sendBinary(WsRemoteEndpointAsync.java:65)
> 
> From what I understand from java doc, RemoteEndpoint.Async.sendBinary
> should not throw IllegalStateException:
> 
>> sendBinary void sendBinary(ByteBuffer data, SendHandler handler)
>> Throws: IllegalArgumentException - if either the data or the handler are 
>> null.
> 
> It is also good to note that RemoEndpoint.Basic (not
> RemoteEndpoint.Async) has the following paragraph in java doc:
> 
>> If the websocket connection underlying this RemoteEndpoint is busy sending a 
>>  message when a call is made to send another one, for example if two threads 
>>  attempt to call a send method concurrently, or if a developer attempts to 
>> send a new message while in the middle of sending an existing one, the send 
>> method called while the connection is already busy may throw an 
>> IllegalStateException.
> 
> 
> Is this expected behaviour from tomcat or a possible implementation bug?

The behaviour is expected. You can't start a new message until the
previous one has finished.

Mark


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to