title: access websocket from a desktop application
body: <p>I have a project with spring-websocket with this setup:</p>
  
  <p><strong>SocketHandler.java</strong></p>
  
  <pre><code>@Component
  public class SocketHandler extends TextWebSocketHandler {
      List&lt;WebSocketSession&gt; sessions = new CopyOnWriteArrayList&lt;&gt;();
  
      @Override
      public void handleTextMessage(WebSocketSession session, TextMessage message) throws InterruptedException, IOException {
          Map&lt;String, String&gt; value = new Gson().fromJson(message.getPayload(), Map.class);
          session.sendMessage(new TextMessage("Hello " + value.get("name") + " !"));
      }
  
      @Override
      public void afterConnectionEstablished(WebSocketSession session) throws Exception {
          sessions.add(session);
      }
  }
  </code></pre>
  
  <p><strong>WebSocketConfig.java</strong></p>
  
  <pre><code>@Configuration
  @EnableWebSocket
  public class WebSocketConfig implements WebSocketConfigurer {
      public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
          registry.addHandler(new SocketHandler(), "/name");
      }
  }
  </code></pre>
  
  <p><strong>index.html</strong></p>
  
  <pre><code>  &lt;table&gt;
      &lt;tr&gt;
        &lt;td&gt;
          &lt;button id="connect" type="button" onclick="connect();"&gt;Connect&lt;/button&gt;
          &lt;button id="disconnect" type="button" disabled="disabled" onclick="disconnect();"&gt;Disconnect&lt;/button&gt;
        &lt;/td&gt;
        &lt;td&gt;
          &lt;label for="name"&gt;What is your name?&lt;/label&gt;
          &lt;input type="text" id="name" placeholder="Your name here..."&gt;
          &lt;button id="send" type="button" onclick="send();"&gt;Send&lt;/button&gt;
        &lt;/td&gt;
      &lt;/tr&gt;
    &lt;/table&gt;
  
    &lt;hr&gt;
  
    &lt;table id="conversation" border="2"&gt;
        &lt;thead&gt;
        &lt;tr&gt;
            &lt;th&gt;Greetings&lt;/th&gt;
        &lt;/tr&gt;
        &lt;/thead&gt;
        &lt;tbody id="greetings"&gt;
        &lt;/tbody&gt;
    &lt;/table&gt;
  </code></pre>
  
  <p><strong>script.js</strong></p>
  
  <pre><code>var ws;
  
  function setConnected(connected) {
      var connect = document.querySelector("#connect");
      var disconnect = document.querySelector("#disconnect");
      var conversation = document.querySelector("#conversation");
      var greetings = document.querySelector("#greetings");
  
      if(connected) {
        connect.setAttribute("disabled", "disabled");
        disconnect.removeAttribute("disabled");
        conversation.style.display = 'block';
      } else {
        connect.removeAttribute("disabled");
        disconnect.setAttribute("disabled", "disabled");
        conversation.style.display = 'none';
      }
  
      greetings.innerHTML = "";
  }
  
  function connect() {
      ws = new WebSocket('ws://localhost:8080/name');
      ws.onmessage = function(text) {
          showGreeting(text.data);
      }
      setConnected(true);
  }
  
  function disconnect() {
      if (ws != null) {
          ws.close();
      }
      setConnected(false);
  }
  
  function send() {
    var name = document.querySelector("#name");
      var data = JSON.stringify({'name': name.value});
    ws.send(data);
  }
  
  function showGreeting(message) {
    var greeting = document.querySelector("#greetings");
    var tr = document.createElement("tr");
    var td = document.createElement("td");
    td.innerText = message;
    tr.appendChild(td);
    greeting.appendChild(tr);
  }
  </code></pre>
  
  <p>I wonder if it's possible develop a desktop client application, for example, with Java/Swing or C++/Qt, which could communicate with this application as if it was a server, receiving the data from the desktop application and broadcast to all clients connected to it.</p>