import http.HttpServerRequest;
@SpringBootApplication
@RestController
public class DemoApplication {
public static void main(String[] args) {
final ConfigurableApplicationContext run = SpringApplication.run(BurstServerApplication.class);
}
// normal request
@GetMapping("hello")
public String hello(@RequestParam String name) {
return "Hello " + name;
}
// upgrade to websocket
@GetMapping("connect")
public void connect(@RequestParam String name, HttpServerRequest request) {
request.upgradeToWebSocket(ws->{
ws.mountOpen(h -> {
ws.send("Hello " + name);
});
});
}
}
评论