Package org.springframework.samples.websocket.echo

Source Code of org.springframework.samples.websocket.echo.EchoWebSocketHandler

package org.springframework.samples.websocket.echo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.WebSocketSession;
import org.springframework.web.socket.handler.TextWebSocketHandler;

/**
* Echo messages by implementing a Spring {@link WebSocketHandler} abstraction.
*/
public class EchoWebSocketHandler extends TextWebSocketHandler {

  private final EchoService echoService;


  @Autowired
  public EchoWebSocketHandler(EchoService echoService) {
    this.echoService = echoService;
  }

  @Override
  public void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception {
    String reply = this.echoService.getMessage(message.getPayload());
    session.sendMessage(new TextMessage(reply));
  }

}
TOP

Related Classes of org.springframework.samples.websocket.echo.EchoWebSocketHandler

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.