mirror of
https://github.com/Dichgrem/Java.git
synced 2026-02-05 04:21:56 -05:00
update:demo8
This commit is contained in:
22
com/study/demo8/TCPClient.java
Normal file
22
com/study/demo8/TCPClient.java
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user