update:demo8

This commit is contained in:
dichgrem
2026-01-04 16:15:25 +08:00
parent e43d2075ba
commit a7c559d270
4 changed files with 101 additions and 0 deletions

View File

@@ -0,0 +1,22 @@
package com.study.demo8;
import java.io.PrintWriter;
import java.net.Socket;
public class TCPClient {
public static void main(String[] args) {
try {
Socket socket = new Socket("localhost", 8888);
System.out.println("Connected to server.");
PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
out.println("Hello Server");
System.out.println("Sent message to server.");
out.close();
socket.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}