title: what use spring multiple handler websocket session service
body: <p>I'm using two Websockethandles(Text, Binary) in the spring(4.3.16.RELEASE)</p>
  <p>The structure of this handler is as follows</p>
  <p>TextHandler(handleMessage) → service &gt; service2</p>
  <p>Binary(sendMessage)</p>
  <p>I want to send binary by calling a websocket session connected to binary handler from service 2 operated by texthandler.
  However, the value of the session is null.</p>
  <p>It is confirmed that the websocket connection works normally
  The session was also confirmed to be normal.
  However, the connection session information could not be retrieved from service 2, so sendMessage is not working</p>
  <p>P.S : I used a translator for this question. Thank you</p>
  <pre><code>@Repository
  public class TextSocketHandler extends TextWebSocketHandler {
  
      private final Logger logger = LoggerFactory.getLogger(TextSocketHandler.class);
  
      private Set&lt;WebSocketSession&gt; textSessionSet = new HashSet&lt;WebSocketSession&gt;();
      public static Map&lt;WebSocketSession, AuthInfoResponse&gt; sessionTimeMap = new HashMap&lt;WebSocketSession, AuthInfoResponse&gt;();
  
      @Autowired
      WsProcessService wsProcessService;
  
      ObjectMapper mapper = new ObjectMapper();
  
      List&lt;WebSocketSession&gt; textWebSocketSessions = null;;
  
      public static Thread thread;
  
      public Set&lt;WebSocketSession&gt; getSessionList() throws Exception {
          return textSessionSet;
      }
  
      @Override
      public void handleMessage(WebSocketSession session, WebSocketMessage&lt;?&gt; message) throws Exception {
          super.handleMessage(session, message);
  
          long time = System.currentTimeMillis();
          if (!textSessionSet.contains(session)) {
              session.close();
          }
  
          AuthInfoResponse authInfoResponse = wsProcessService.processService(new AuthInfoResponse(), session, message, textSessionSet);
          //session.sendMessage();
          }
      }
  }
  </code></pre>
  <hr />
  <pre><code>@Repository
  public class BinarySocketHandler extends BinaryWebSocketHandler {
  
      private final Logger logger = LoggerFactory.getLogger(BinarySocketHandler.class);
  
      private Set&lt;WebSocketSession&gt; binarySessionSet = new HashSet&lt;WebSocketSession&gt;();
      public static Map&lt;WebSocketSession, AuthInfoResponse&gt; sessionTimeMap = new HashMap&lt;WebSocketSession, AuthInfoResponse&gt;();
  
      ObjectMapper mapper = new ObjectMapper();
  
      List&lt;WebSocketSession&gt; binaryWebSocketSessions = null;
  
      public static Thread thread;
  
      public Set&lt;WebSocketSession&gt; getSessionList() throws Exception {
          return binarySessionSet;
      }
      ......
  }
  </code></pre>
  <hr />
  <pre><code>public class service2{
      @Autowired
      BinarySocketHandler binarySocketHandler;
  
      @Autowired
      TextSocketHandler textSocketHandler;
  
      private Set&lt;WebSocketSession&gt; textSessionSet = new HashSet&lt;WebSocketSession&gt;();
  
      private Set&lt;WebSocketSession&gt; binarySessionSet = new HashSet&lt;WebSocketSession&gt;();
  
      public ByteString createFileTextToSpeechSampleSource(String text, String langCode) throws Exception {
          ByteString audioContents = textToSpeechWork.synthesizeText(text, langCode);
          ByteBuffer audioBuffer = audioContents.asReadOnlyByteBuffer();
  
          testSocket(audioBuffer);
          return audioContents;
      }
  
      public void testSocket(ByteBuffer byteBuffer) throws Exception {
  
          Set&lt;WebSocketSession&gt; biSessionList = binarySocketHandler.getSessionList();
          Set&lt;WebSocketSession&gt; txSessionList = textSocketHandler.getSessionList();
          _logger.info(&quot;biSessionList : {}&quot;, biSessionList);
          _logger.info(&quot;txSessionList : {}&quot;, txSessionList);
  
          _logger.info(&quot;textSessionSet : {}&quot;, textSessionSet);
          _logger.info(&quot;binarySessionSet : {}&quot;, binarySessionSet);
  
          for (WebSocketSession wsSess : wsSessionList) {
              try {
                  wsSess.sendMessage(new BinaryMessage(byteBuffer)); 
              } catch (Exception e) {
  
              }
          }
      }
  }
  </code></pre>
  <hr />