Ah, it is now okay. I was using Tyrus WebSocket Client and WebSocket message were coming asynchronously without calling webSocket.request(1) like method there. It is something like releasing a lock from semaphore.
A WebSocket server can send any message at any time to any client, so how a client will be able to get any message at any time with this API ? For example, if our server pushes new stock exchange data to our client, how can I get this multiple data from server when they come ? Thanks 2016-08-18 14:23 GMT+03:00 Pavel Rappo <pavel.ra...@oracle.com>: > > > On 18 Aug 2016, at 11:44, Rahman USTA <rahman.usta...@gmail.com> wrote: > > > > Hmm, how should I refactor it on my code to make it clear? > > Pardon, I don't think I fully understand the question. > > In the API you have two _independent_ points where you can start your work. > > 1. When an instance of WebSocket is ready the CompletableFuture returned > from > WebSocket.Builder.buildAsync completes with this instance. > > 2. When an instance of WebSocket is ready WebSocket.Listener.onOpen is > invoked > with this instance. > > These instances correspond to the same communication (or > session/connection if > you like). > > That's it. There's no guaranteed order in which these 2 events (obtaining > an > instance) occur. By default the point where the initial request is made is > WebSocket.Listener.onOpen. > > When and where you make consecutive requests usually depends on your > readiness > to handle them. So for instance, if you were writing an echo server you > might > decide to request the next message when the previous has been sent: > > CompletableFuture<?> onText(WebSocket webSocket, Text payload, boolean > isLast) { > > return webSocket.sendText(payload, isLast) > .thenRun(() -> webSocket.request(1)); > } > > Just choose what suits you best, I guess. > > -- Rahman USTA Istanbul JUG https://github.com/rahmanusta <http://www.kodcu.com/>