forked from eugenejade/JavaTPCProject
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProject06A_Client.java
More file actions
26 lines (24 loc) · 826 Bytes
/
Project06A_Client.java
File metadata and controls
26 lines (24 loc) · 826 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import java.net.*;
import java.util.Scanner;
import java.io.*;
public class Project06A_Client {
public static void main(String[] args) {
try {
Socket socket=new Socket("127.0.0.1", 9999); // -------->accept()
System.out.println("Connection Success!");
Scanner scanner=new Scanner(System.in);
String message=scanner.nextLine();
OutputStream out=socket.getOutputStream();
DataOutputStream dos=new DataOutputStream(out);
dos.writeUTF(message);
InputStream in=socket.getInputStream();
DataInputStream dis=new DataInputStream(in);
System.out.println("Receive:"+dis.readUTF());
dis.close();
dos.close();
socket.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}