WangHan
2025-04-03 a1b85ef72062ca80db35546e4216dd564f3e0f57
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
package com.ctoms.tcp;
 
import com.iplatform.tcp.util.ws.WebDataResponse;
import com.walker.infrastructure.utils.JsonUtils;
import com.walker.infrastructure.utils.NumberGenerator;
 
public class WebsocketDemo {
 
    public void sendDataFormat(){
        WebDataResponse msg = new WebDataResponse();
        msg.setMessageId(NumberGenerator.getLongSequenceId());
        msg.setName("shikeying");    // 指定用户发送,该id与浏览器端注册的id保持一致。
        msg.setData("你好,这是推送给浏览器的内容,一般是JSON格式。");
        try {
            System.out.println(JsonUtils.objectToJsonString(msg));
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}