title: WebClient vs WebSocketClient
body: <p>I am trying my hands on spring webflux. I am a bit confused on why do we need WebSocketClient, when we have WebClient. </p>
  
  <p>Prior to Spring 5  we had two issues<br>
  1. REST call is a blocking call because we were using HttpClient. 
  And<br>
  2. It was mainly pull mechanism from the client side whenever we need data.   </p>
  
  <p>But with Spring 5 and web flux module, we can have something like this on server side</p>
  
  <pre><code>@Bean
      public RouterFunction&lt;ServerResponse&gt; routerFunction () {
          return
                  route(
                          GET("/streaming"),  serverRequest -&gt; {
  
                              Flux&lt;Integer&gt; flow = Flux.just(1, 2, 3, 4, 5).delayElements(Duration.ofSeconds(2)).doOnEach(entry -&gt; System.out.println(entry.get()));
                              return ServerResponse.ok().contentType(MediaType.APPLICATION_STREAM_JSON).body(BodyInserters.fromPublisher(flow, Integer.class));
                          }
                  )
          ;
      }
  </code></pre>
  
  <p>and we can solve two issues mentioned above using WebClient from client side</p>
  
  <pre><code>WebClient.create("http://localhost:8080")
          .get()
          .uri("/streaming")
          .accept(MediaType.APPLICATION_STREAM_JSON)
          .exchange()
          .flatMap(response -&gt; response.bodyToMono(String.class))
          .subscribe(System.out::println);
  
      IntStream.range(0,10).forEach(i -&gt; {
        try {
          Thread.sleep(2000);
          System.out.println("non blocking");
        } catch (InterruptedException e) {
          e.printStackTrace();
        }
      });
  </code></pre>
  
  <p>In this case firstly, the REST call is non blocking which can be validated by the fact that the next statement is executed immediately. And also data is being pushed from  a server side and not pulled from client side.</p>
  
  <p>So if we can do this using WebClient where would I need WebSocketClient.</p>