新版仿ok交易所-后端
1
zj
2026-02-02 12f937c17d86b0778dd6f92bec90b2cc48aa60b5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package com.yami.trading.api.websocket;
 
import lombok.AllArgsConstructor;
import lombok.Data;
 
import javax.websocket.Session;
import javax.websocket.server.PathParam;
import java.io.IOException;
 
@Data
public class WebSocketSession {
    /**
     * 与某个客户端的连接会话,需要通过它来给客户端发送数据
     */
    private Session session;
    private long timeStr;
    private String setKey;
    private String type;
    private String param;
 
    public WebSocketSession(Session session, long timeStr, String type, String param) {
        this.session = session;
        this.timeStr = timeStr;
        this.type = type;
        this.param = param;
        this.setKey = session.getId() + "_" + type + "_" + param;
    }
 
    /**
     * 单发消息
     */
    public void sendMessage(String message) throws IOException {
        // 阻塞式(同步)
        // this.session.getBasicRemote().sendText(message);
        // 非阻塞式(异步)
        this.session.getAsyncRemote().sendText(message);
    }
 
}