HTTP/2 Client WebSocket support

Pavel Rappo pavel.rappo at oracle.com
Thu Aug 18 10:35:11 UTC 2016


This API was designed to work within "reactive pull" model [1]. In other words,
in order to receive messages you must first request them ( see
WebSocket.request(long) ).

As far as I can see, your code requests nothing. If you want to disable reactive
pull completely, you can request Long.MAX_VALUE messages once and never worry
about that ever again.

Thanks.

--------------------------------------------------------------------------------
[1] http://www.reactive-streams.org

> On 18 Aug 2016, at 11:17, Rahman USTA <rahman.usta.88 at gmail.com> wrote:
> 
> Hi Pavel;
> 
> My WebSocket client is;
> 
> URI uri = URI.create("ws://localhost:8080/merhaba");
>         MessageListener messageListener = new MessageListener();
>         
>         WebSocket.newBuilder(uri, messageListener)
>                 .buildAsync()
>                 .join();
> 
> My MessageListener is here;
> 
> public class MessageListener implements WebSocket.Listener {
> 
>     @Override
>     public void onOpen(WebSocket webSocket) {
>         webSocket.sendText("Ali");
>         webSocket.sendText("Ata");
>         webSocket.sendText("Bak");
>     }
> 
>     @Override
>     public CompletionStage<?> onText(WebSocket webSocket, CharSequence message, WebSocket.MessagePart part) {
>         System.out.println("Gelen mesaj: " + message);
>         return null;
>     }
> 
>     @Override
>     public void onClose(WebSocket webSocket, Optional<WebSocket.CloseCode> code, String reason) {
>         System.out.println("Closed..");
>     }
> 
>     @Override
>     public void onError(WebSocket webSocket, Throwable error) {
>         error.printStackTrace();
>     }
> }
> 
> And the ServerEndpoint;
> 
> @ServerEndpoint("/merhaba")
> public class MerhabaSoket {
>     
>     @OnError
>     public void onerror(Throwable thr) {
>         thr.printStackTrace();
>     }
> 
>     @OnMessage
>     public void onmessage(Session session, String message) throws IOException {
>         session.getBasicRemote().sendText(message);
>     }
> 
> }
> 
> Thanks
> 
> 
> 2016-08-18 13:08 GMT+03:00 Pavel Rappo <pavel.rappo at oracle.com>:
> Hi,
> 
> Though it's not yet complete and some bugs are expected [1], I strongly suspect
> the reason you don't receive any messages from the server might be due to
> MessageListener implementation. Could you please post its code? Thanks.
> 
> --------------------------------------------------------------------------------
> [1] https://bugs.openjdk.java.net/browse/JDK-8161333?jql=labels%20%3D%20websocket%20and%20labels%20%3D%20jep-110%20and%20status%20not%20in%20(resolved%2C%20closed)
> 
> > On 18 Aug 2016, at 10:38, Rahman USTA <rahman.usta.88 at gmail.com> wrote:
> >
> > Hello;
> >
> > I try the WebSocket API in java.httpclient module;
> >
> > URI uri = URI.create("ws://localhost:8080/merhaba");
> >         MessageListener messageListener = new MessageListener();
> >
> >         WebSocket.newBuilder(uri, messageListener)
> >                 .buildAsync()
> >                 .join();
> >
> > I have this code, it connects to WebSocket server, but after connection it doesn't get messages sent from server. Is this feature ready to test?
> >
> > Thanks.
> >
> > --
> > Rahman USTA
> > Istanbul JUG
> > https://github.com/rahmanusta
> 
> 
> 
> 
> -- 
> Rahman USTA
> Istanbul JUG
> https://github.com/rahmanusta



More information about the net-dev mailing list