Epoll 环境为Linux 内核2.6 以上版本 Windows下不能启动
1:判断Linux环境
public static boolean isOSLinux() { Properties prop = System.getProperties(); String os = prop.getProperty("os.name"); System.out.println(os); if (os != null && os.toLowerCase().indexOf("linux") > -1) { return true; } else { return false; } }
if(isOSLinux()){
//使用Linux Epoll模型
log.info("启用Epoll");
config.setUseLinuxNativeEpoll(true);
}
2:pom.xml配置
参考地址: https://www.jianshu.com/p/bb3718226f36
<dependency> <groupId>com.corundumstudio.socketio</groupId> <artifactId>netty-socketio</artifactId> <version>1.7.13</version> <exclusions> <exclusion> <groupId>io.netty</groupId> <artifactId>netty-common</artifactId> </exclusion> <exclusion> <groupId>io.netty</groupId> <artifactId>netty-transpor</artifactId> </exclusion> <exclusion> <groupId>io.netty</groupId> <artifactId>netty-buffer</artifactId> </exclusion> <exclusion> <groupId>io.netty</groupId> <artifactId>netty-handler</artifactId> </exclusion> <exclusion> <groupId>io.netty</groupId> <artifactId>netty-codec-http</artifactId> </exclusion> <exclusion> <groupId>io.netty</groupId> <artifactId>netty-codec</artifactId> </exclusion> <exclusion> <groupId>io.netty</groupId> <artifactId>netty-resolver</artifactId> </exclusion> <exclusion> <groupId>io.netty</groupId> <artifactId>netty-transport</artifactId> </exclusion> <exclusion> <groupId>io.netty</groupId> <artifactId>netty-transport-native-epoll</artifactId> </exclusion> </exclusions> </dependency> <!-- 客户端 --> <dependency> <groupId>io.socket</groupId> <artifactId>socket.io-client</artifactId> <version>1.0.0</version> </dependency> <dependency> <groupId>io.netty</groupId> <artifactId>netty-all</artifactId> <version>4.1.16.Final</version> </dependency>
3:启动成功后如图,有一个异常警告
处理方式
参考地址: https://github.com/robymus/netty-socketio/commit/fcc7d33df843eb2720529540ac1c37ffa0e262a4
4: SO_LINGER 什么意思呢,
参考地址: https://www.jianshu.com/p/0bff7c020af2
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)
2017-09-26 Socket IO Web实时推送