WebSocketServer
2024-10-21 10:16:48
@Component
@ServerEndpoint(value = "/endpoint/ws")
public class WebSocketServer {
private final Logger logger = LoggerFactory.getLogger(getClass());
private static final AtomicInteger onlineCount = new AtomicInteger();
@OnOpen
public void onOpen(Session session, @PathParam("sid") String sid) {
//在线数加1
onlineCount.incrementAndGet();
logger.info("新窗口监听 {}, 当前在线人数 {}",sid,onlineCount.get());
} @OnClose
public void onClose() {
//在线数减1
onlineCount.decrementAndGet();
logger.info("连接关闭, 当前在线人数为 {}",onlineCount.get());
} @OnError
public void onError(Session session, Throwable error) {
logger.warn("发生错误, 非正常关闭 {}, 当前在线人数为 {}", onlineCount.get());
}
}
最新文章
- Linux连接Internet
- web项目中,视图层中关于相对路径和绝对路径
- JS魔法堂:jsDeferred源码剖析
- Spring学习之第一个AOP程序
- 一些常用的vim设置
- Java实现批量下载《神秘的程序员》漫画
- JavaScript当离开页面时可以进行的操作
- 【杂记】SQL篇
- Codeforces 713D Animals and Puzzle
- SPOJ 274 Johnny and the Watermelon Plantation(TLE)
- Spark 读写hive 表
- hdu1698 线段树区间更新
- double free or corruption错误
- haxe相关的计划安排
- [Oralce][InMemory]如何确定一个表已经被Populate 到In Memory 中?
- A - Longest k-Good Segment (尺取法)
- Mysql截取和拆分字符串函数用法
- 7.xamarin.android 发布签名与控制apk大小
- Windows Azure 初体验
- Bootstrap学习笔记(9)--模态框(登录/注册弹框)
热门文章
- (二)limit的高级用法
- [LeetCode] 265. Paint House II 粉刷房子
- centos 安装 swoole_framework 框架
- npm创建angular项目
- QT QML 在qml中自定义信号
- (五)linux 学习 --重定向
- Dubbo学习摘录(一)
- Unity的学习笔记(UGUI文本逐个字输出)
- pytorch 0.4.0迁移指南
- serviceBehaviors_dataContractSerializer_maxItemsInObjectGraph 关键**Behavior