-
Notifications
You must be signed in to change notification settings - Fork 0
/
Client.java
31 lines (26 loc) · 1008 Bytes
/
Client.java
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
27
28
29
30
31
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.util.Scanner;
public class Client {
public static void main(String[] args) throws IOException {
System.out.println("Client started.");
Socket socket = new Socket("127.0.0.1", 6000);
System.out.println("Client connected.");
ObjectOutputStream oUs = new ObjectOutputStream(socket.getOutputStream());
ObjectInputStream oIs = new ObjectInputStream(socket.getInputStream());
Scanner scanner = new Scanner(System.in);
System.out.println("Enter a message here : ");
String msg = scanner.nextLine();
//sent to server
oUs.writeObject(msg);
try {
//received from server
Object sMsg = oIs.readObject();
System.out.println("From server : " + (String) sMsg);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
}