KKSU
2024-09-30 36be00e0f3cbe0d559c646fd2977e6e3a74aa6f9
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
package com.xcong.excoin.netty.common;
 
import com.alibaba.fastjson.JSONObject;
import com.xcong.excoin.netty.bean.ResponseBean;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
 
/**
 * @author wzy
 * @date 2019-05-14
 */
public class NettyTools {
 
 
    /**
     * socket字符串传输转码
     *
     * @param msg
     * @return
     */
    public static ByteBuf textBytes(String msg) {
        return Unpooled.copiedBuffer((msg + "_split").getBytes());
    }
 
    public static TextWebSocketFrame wsSendMsg(ResponseBean responseBean) {
        String res = JSONObject.toJSONString(responseBean);
        return new TextWebSocketFrame(res);
    }
 
    public static TextWebSocketFrame webSocketBytes(String msg) {
        return new TextWebSocketFrame(msg);
    }
 
    public static TextWebSocketFrame webSocketJson(Object object) {
        return webSocketBytes(JSONObject.toJSONString(object));
    }
}