TCP链接
首先创建子类实现 ClientChannelRead 接口,且实现方法 tackle 在 tackle 方法中编写自己的业务代码
*只能在子类注入 model接口,在其他地方注入容易造成数据链接丢失问题。示例如下:
package dynamic;
import dynamic.model.Ground_Station;
import microbee.http.annotation.ModelResources;
import microbee.http.utills.nettool.ClientChannelRead;public class TestClient implements ClientChannelRead {
@ModelResources
Ground_Station ground_station;@Override
public void tackle(String msg) {
System.out.println(msg);
System.out.println(ground_station.gainOneById(7).get("name"));
}
}
获取客户端链接
String host = "127.0.0.1";
int port = 8888;long reconctfrqs =1000;//短线重连时间msSocketClient socketClient = SocketClient.getSocketClient(host,port,reconctfrqs ,new TestClient());
向服务端发送数据
socketClient.sendData("dddddd");
本文档来自—microbee-http 丨 软件开发框架平台
扫一扫