import TCPNet.TCPClient; import org.junit.Test; /* * @Author: Wang Feng * @Description: * @Version: 1.0.0 * @Date: 16:58 2021/6/22 * @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室 */ public class TestMain { @Test public void testConnectionServer(){ TCPClient tcpClient = new TCPClient("121.15.171.82", 12345) { @Override protected void onDataReceive(byte[] bytes, int size) { String content = "TCPServer say :" + new String(bytes, 0, size); System.out.println(content); } }; tcpClient.connect(); // 连接TCPServer if (tcpClient.isConnected()) { //发送数据 String outContent = "TCPClient say hello"; tcpClient.send(outContent.getBytes()); } //关闭连接 tcpClient.close(); } }