Socket 对外接口 (二)

1. 引用库和权限

  1.1 权限添加

    <!--网络权限-->
    <uses-permission android:name="android.permission.INTERNET" />
    <!--网络状态-->
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

  2.1 引用库

    // GSON 格式转换
    implementation 'com.google.code.gson:gson:2.10.1'

2. 定义发送消息体格式

  2.1 无回调标识发送消息基类,AbsSuperSender.java

/**
 * @Description: 无回调标识发送消息基类
 */
public class AbsSuperSender extends SuperSender {

    @Override
    public byte[] pack() {
        return new Gson().toJson(this).getBytes();
//         byte[] body = new Gson().toJson(this).getBytes();
//        //如果没有设置消息协议,则直接发送消息
//        if (IOSocket.getInstance().getDefOptions().getMessageProtocol() == null) {
//            return body;
//        }
//   

猜你喜欢

转载自blog.csdn.net/u011193452/article/details/129947956