mirror of
https://github.com/Dichgrem/Java.git
synced 2026-02-05 07:31:57 -05:00
23 lines
595 B
Java
23 lines
595 B
Java
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();
|
|
}
|
|
}
|
|
}
|