怎么用netty开发一个同时提供http和websocket的服务?

Sky

项目地址:
https://github.com/fzdwx/sky

依赖


  io.github.fzdwx
  sky-http-springboot-starter
  0.10.6

启动类

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);
            });
        });
    }
}

问题

当前项目对servlet的支持不是很好,也不支持filter等servlet提供的功能。

你可能感兴趣的:(javawebsocket)