Skip to main content

公共模块编写

公共模块

<dependency>
<groupId>org.t-io</groupId>
<artifactId>tio-core</artifactId>
<version>3.5.0.v20190822-RELEASE</version>
</dependency>
  • 定义Packet
package org.tio.study.helloworld.common;

import org.tio.core.intf.Packet;

/**
* @author tanyaowu
*/
public class HelloPacket extends Packet {
private static final long serialVersionUID = -172060606924066412L;
public static final int HEADER_LENGHT = 4;//消息头的长度
public static final String CHARSET = "utf-8";
private byte[] body;

/**
* @return the body
*/
public byte[] getBody() {
return body;
}

/**
* @param body the body to set
*/
public void setBody(byte[] body) {
this.body = body;
}
}
  • 定义服务器端和客户端都用得到的常量
package org.tio.study.helloworld.common;

/**
*
* @author tanyaowu
* 2017年3月30日 下午7:05:54
*/
public interface Const {
/**
* 服务器地址
*/
public static final String SERVER = "127.0.0.1";

/**
* 监听端口
*/
public static final int PORT = 6789;

/**
* 心跳超时时间
*/
public static final int TIMEOUT = 5000;
}