1
zyy
2 days ago 4fefff17528a878d345ff3311c297a66a671b8d6
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.huobi.websocket;
 
import lombok.Data;
 
import javax.websocket.Session;
import java.io.IOException;
 
@Data
public class WebSocketSession {
    /**
     * 与某个客户端的连接会话,需要通过它来给客户端发送数据
     */
    private Session session;
    private long timeStr;
    private String setKey;
    private String type;
    private String param;
    private String lang;
 
    public WebSocketSession(Session session, long timeStr, String type, String param, String lang) {
        this.session = session;
        this.timeStr = timeStr;
        this.type = type;
        this.param = param;
        this.setKey = session.getId() + "_" + type + "_" + param;
        this.lang = lang;
    }
 
    /**
     * 单发消息
     */
    public void sendMessage(String message) throws IOException {
        // 阻塞式(同步)
        // this.session.getBasicRemote().sendText(message);
        // 非阻塞式(异步)
        this.session.getAsyncRemote().sendText(message);
    }
 
}