当前位置:网站首页>[TiO websocket] III. The TiO websocket server can send messages to users anywhere
[TiO websocket] III. The TiO websocket server can send messages to users anywhere
2022-06-11 09:20:00 【Asurplus、】
In the last article , We have successfully built our websocket The server , And can successfully communicate with the server , This article will lead you to realize that you can send messages to users anywhere
1、 Principle analysis
tio-websocket-server The method of sending messages to users in is as follows :
Tio.sendToUser(channelContext.tioConfig, userId, wsResponse);
- channelContext.tioConfig, Refer to the whole websocket Configuration information , Can pass ChannelContext.tioConfig obtain
- userId: The receiver id
- wsResponse: The response object , Be similar to httpServletResponse
We are in the message processing class MyWsMsgHandler Easy to get in ChannelContext object , We can statically call Tio Various api 了
however , If not in Message processing class MyWsMsgHandler in , We won't get ChannelContext object , We need to be in websocket In the configuration class ServerTioConfig Defined as a global variable , So we can send messages anywhere
2、 reform websocket Configuration class
import com.asurplus.tio.websocket.handle.MyWsMsgHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.tio.server.ServerTioConfig;
import org.tio.websocket.server.WsServerStarter;
import java.io.IOException;
/** * websocket Configuration class */
@Configuration
public class WebSocketConfig {
/** * Injection message processor */
@Autowired
private MyWsMsgHandler myWsMsgHandler;
/** * TIO-WEBSOCKET Configuration information */
public static ServerTioConfig serverTioConfig;
/** * Start class configuration * * @return * @throws IOException */
@Bean
public WsServerStarter wsServerStarter() throws IOException {
// Set up the processor
WsServerStarter wsServerStarter = new WsServerStarter(6789, myWsMsgHandler);
// Get ServerTioConfig
serverTioConfig = wsServerStarter.getServerTioConfig();
// Set heartbeat timeout , Default :1000 * 120
serverTioConfig.setHeartbeatTimeout(1000 * 120);
// start-up
wsServerStarter.start();
return wsServerStarter;
}
}
such , We define a global variable serverTioConfig, Where needed , It only needs WebSocketConfig.serverTioConfig Can get
3、 Use demonstration
Tio.sendToUser(WebSocketConfig.serverTioConfig, "1", wsResponse);
Tio.sendToGroup(WebSocketConfig.serverTioConfig, "1234", wsResponse);
So we can get it anywhere websocket Configuration information , For users perhaps group Sent a message
If you find deficiencies in reading , Welcome to leave a message !!!
边栏推荐
- How to deal with these problems in the factory production process?
- Machine learning notes - convolutional neural network memo list
- Talk about reading the source code
- 面试题 17.10. 主要元素
- PD chip ga670-10 for OTG while charging
- Concurrent programming
- Machine learning notes - the story of master kaggle Janio Martinez Bachmann
- kubelet Error getting node 问题求助
- MSF evasion模块的使用
- 86. separate linked list
猜你喜欢

MSF evasion模块的使用

Opencv CEO teaches you to use oak (V): anti deception face recognition system based on oak-d and depthai
![报错[DetectionNetwork(1)][warning]Network compiled for 6 shaves,maximum available 10,compiling for 5 s](/img/54/f42146ae649836fe7070ac90f2160e.png)
报错[DetectionNetwork(1)][warning]Network compiled for 6 shaves,maximum available 10,compiling for 5 s

PD chip ga670-10 for OTG while charging
![[FAQ for novices on the road] about data visualization](/img/a1/d15e286c3c886a8d3a4ac3eb165748.png)
[FAQ for novices on the road] about data visualization

Blinn Phong reflection model

MSF基于SMB的信息收集

openstack详解(二十三)——Neutron其他配置、数据库初始化与服务启动

实现边充边OTG的PD芯片GA670-10

OpenCV OAK-D-W广角相机测试
随机推荐
Redis source code analysis hash object (z\u hash)
机器学习笔记 - 使用TensorFlow的Spatial Transformer网络
Exclusive interview with PMC member Liu Yu: female leadership in Apache pulsar community
876. intermediate node of linked list
Error [detectionnetwork (1)][warning]network compiled for 6 shapes, maximum available 10, compiling for 5 S
Machine learning notes - convolutional neural network memo list
企业需要考虑的远程办公相关问题
Sed explanation of shell script (SED command, sed -e, sed s/ new / old /...)
Device = depthai Device(““, False) TypeError: _init_(): incompatible constructor arguments.
报错device = depthai.Device(““, False) TypeError: _init_(): incompatible constructor arguments.
【服装ERP】施行在项目中的重要性
Fabric.js 動態設置字號大小
Complexity analysis of matrix inversion operation (complexity analysis of inverse matrix)
Opencv CEO teaches you to use oak (IV): create complex pipelines
Error [error] input tesnor exceeded available data range [neuralnetwork (3)] [error] input tensor '0' (0)
844. compare strings with backspace
MSF给正常程序添加后门
CUMT learning diary - theoretical analysis of uCOSII - Textbook of Renzhe Edition
【芯片方案】红外人体测温仪方案设计
Machine learning notes - the story of master kaggle Janio Martinez Bachmann