Spaces:
Sleeping
Sleeping
package ai.giskard.learnspringwebsockets; | |
import org.springframework.context.annotation.Bean; | |
import org.springframework.context.annotation.Configuration; | |
import org.springframework.web.socket.CloseStatus; | |
import org.springframework.web.socket.WebSocketHandler; | |
import org.springframework.web.socket.WebSocketMessage; | |
import org.springframework.web.socket.WebSocketSession; | |
import org.springframework.web.socket.config.annotation.EnableWebSocket; | |
import org.springframework.web.socket.config.annotation.WebSocketConfigurer; | |
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry; | |
public class WebSocketConfig implements WebSocketConfigurer { | |
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) { | |
registry.addHandler(myHandler(), "/ws"); | |
} | |
public WebSocketHandler myHandler() { | |
return new WebSocketHandler() { | |
public void afterConnectionEstablished(WebSocketSession session) throws Exception { | |
System.out.println("afterConnectionEstablished"); | |
} | |
public void handleMessage(WebSocketSession session, WebSocketMessage<?> message) throws Exception { | |
System.out.println("handleMessage"); | |
} | |
public void handleTransportError(WebSocketSession session, Throwable exception) throws Exception { | |
System.out.println("handleTransportError"); | |
} | |
public void afterConnectionClosed(WebSocketSession session, CloseStatus closeStatus) throws Exception { | |
System.out.println("afterConnectionClosed"); | |
} | |
public boolean supportsPartialMessages() { | |
return false; | |
} | |
}; | |
} | |
} |