leafSpring Boot

netty-socket-io.hostname=localhost
netty-socket-io.port=9092
netty-socket-io.ping-timeout=60000
netty-socket-io.ping-interval=25000
circle-info

只需添加 properties/yml 即可使用默认设置运行服务器。如果您想添加 SocketIOServer bean,请排除默认服务器

自定义 SocketIOServer Bean

@Configuration
public class SocketIOConfig {
    
    @Bean
    public SocketIOServer socketIOServer() {
        Configuration config = new Configuration();
        config.setHostname("localhost");
        config.setPort(9092);
        return new SocketIOServer(config);
    }
}

主应用程序

使用注解的事件处理器

您可以使用注解来定义事件处理器:

异常处理

完整示例

在以下位置查看完整示例 netty-socketio-examples-spring-boot-basearrow-up-right 模块。

最后更新于

这有帮助吗?