⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tcpclient.java

📁 一个用JAVA作的TCP通信的例子
💻 JAVA
字号:
package tcp;

import java.io.*;
import java.net.*;

public class TcpClient {
    public static void main(String[] args) throws IOException {
        Socket soc = null;
        PrintStream out = null;
        String ip = "100.10.0.99";
        try {
            soc = new Socket(ip, 3012);
            out = new PrintStream(soc.getOutputStream());
            out.println("testa");
            out.flush();
            out.println("testb");
            out.flush();
            out.println("testc");
            out.flush();
            out.println("testd");
            out.flush();
            soc.close();
            

            // 如果Server有回应,也可以接收
            DataInputStream in = new DataInputStream(soc.getInputStream());
            String str = in.readLine();
            System.out.println("Server send: " + str);
            in.close();
        } catch (Exception e) {
        } finally {
            out.close();
            soc.close();
            System.exit(0);
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -