怎么用netty开发一个同时提供http和websocket的服务?
文章目录
Sky
项目地址:
https://github.com/fzdwx/sky
依赖
<dependency>
<groupId>io.github.fzdwx</groupId>
<artifactId>sky-http-springboot-starter</artifactId>
<version>0.10.6</version>
</dependency>启动类
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提供的功能。
评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论