-
Notifications
You must be signed in to change notification settings - Fork 0
/
Client.java
47 lines (36 loc) · 1.03 KB
/
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//package sockets_lab_2;
import java.io.*;
import java.net.*;
import java.util.Scanner;
public class Client {
public static void main(String args[]) {
String recmsg;
String sendmsg;
Socket client;
Scanner input = new Scanner(System.in);
try {
//Making conenction with server
client = new Socket("localhost", 2225);
System.out.println("Request sent successfully");
boolean b = true;
while (b == true) {
// server msg receive!
BufferedReader br = new BufferedReader(new InputStreamReader(client.getInputStream()));
recmsg = br.readLine();
System.out.println(recmsg);
// Client msg sending to server!
PrintWriter pw = new PrintWriter(client.getOutputStream(), true);
// pw.println(args[0]);
System.out.print("Cient: ");
sendmsg = input.nextLine();
pw.println("Client: " + sendmsg);
if (sendmsg.equals("exit")) {
b = false;
client.close();
}
}
} catch (Exception ex) {
System.out.println(ex);
}
}
}