-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLookupContent.java
More file actions
37 lines (32 loc) · 1.03 KB
/
LookupContent.java
File metadata and controls
37 lines (32 loc) · 1.03 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
import java.util.*;
import java.lang.Runtime;
import java.io.*;
import java.lang.reflect.Array;
import java.net.*;
public class LookupContent {
public static void main(String[] args) {
String host = null;
int port = 0;
long key = 0;
if ( args.length == 3 ) {
host = args[0];
port = Integer.parseInt(args[1]);
key = Long.parseLong(args[2]);
}
try {
Socket next = new Socket(host, port);
Message msg = new Message(CMD.LOOKUPCONTENT, new String[] { host, Integer.toString(port), Long.toString(key) });
ObjectOutputStream outStream = new ObjectOutputStream(next.getOutputStream());
ObjectInputStream iStream = new ObjectInputStream(next.getInputStream());
outStream.writeObject(msg);
String content = (String) iStream.readObject();
if (content != null)
System.out.println(content);
else
System.err.println("Error: no such content");
} catch (Exception e) {
System.err.println("Error: no such peer");
}
}
}
// 10.20.177.174 10000