WsRemoteEndpointImplBase.sendBinary is not synchronized. And there's no way to detect the state outside. client -> server -> client -> server The second time client call sendBinary may fail due to the race condition of stateMachine.binaryStart and stateMachine.complete 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.sendBytes(WsRemoteEndpointImplBase.java:131) at org.apache.tomcat.websocket.WsRemoteEndpointBasic.sendBinary(WsRemoteEndpointBasic.java:43)
The client knows that it called sendBinary() and that that call has not returned. The client therefore *does* know that it should not make another call to sendBinary(). Keeping track of all of this is a client responsibility. (If you want to change that, lobby the WebSocket EG). Note the Javadoc for RemoteEndpoint.Basic: file:///D:/specs/tc8/ws/ws-jsr-356-1.1-final-javadoc/javax/websocket/RemoteEndpoint.Basic.html
(In reply to Mark Thomas from comment #1) > Note the Javadoc for RemoteEndpoint.Basic: > file:///D:/specs/tc8/ws/ws-jsr-356-1.1-final-javadoc/javax/websocket/ > RemoteEndpoint.Basic.html This link might work a little better: http://download.oracle.com/otndocs/jcp/websocket-1_1-mrel-spec/index.html
(In reply to Chuck Caldarale from comment #2) > (In reply to Mark Thomas from comment #1) > > Note the Javadoc for RemoteEndpoint.Basic: > > file:///D:/specs/tc8/ws/ws-jsr-356-1.1-final-javadoc/javax/websocket/ > > RemoteEndpoint.Basic.html > > This link might work a little better: > http://download.oracle.com/otndocs/jcp/websocket-1_1-mrel-spec/index.html The above is for the entire JSR 356; for the online specific reference: http://docs.oracle.com/javaee/7/api/javax/websocket/RemoteEndpoint.Basic.html