-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.java
More file actions
46 lines (40 loc) · 1.3 KB
/
client.java
File metadata and controls
46 lines (40 loc) · 1.3 KB
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
import java.net.*;
import javax.xml.crypto.Data;
import java.io.*;
import java.util.Scanner;
public class client {
public static void main(String[] args) {
Socket s = null;
DataOutputStream out = null;
DataInputStream in = null;
BufferedReader d = null;
try {
s = new Socket("localhost", 6379);
System.out.println("Connected to Redis server...");
out = new DataOutputStream(s.getOutputStream());
in = new DataInputStream(s.getInputStream());
d = new BufferedReader(new InputStreamReader(System.in));
}catch (Exception e) {
e.printStackTrace();
}
String msg = "";
while(!msg.equals("exit")){
try{
msg = d.readLine();
out.writeUTF(msg);
System.out.println("Server response: " + in.readUTF());
}
catch(IOException i){
System.out.println(i);
break;
}
}
try{
s.close();
in.close();
out.close();
} catch(IOException i){
System.out.println(i);
}
}
}