Commit f3244eda authored by Rakhmatullah Yoga Sutrisna's avatar Rakhmatullah Yoga Sutrisna
Browse files

sendfind solved

parent 57eca70a
......@@ -92,13 +92,12 @@ public class ClientHandler extends Thread {
List<Object> offer = new ArrayList<>();
List<Object> temp = new ArrayList<>();
System.out.println(TrackerListener.serverList.length());
for(int i=0; i<TrackerListener.serverList.length(); i++) {
JSONObject obj = TrackerListener.serverList.getJSONObject(i);
if(!obj.getString("ip").equals(InetAddress.getLocalHost().getHostAddress())) {
System.out.println("masuk "+obj.getString("ip")+", "+obj.getInt("port"));
Socket p2p = new Socket(obj.getString("ip"), obj.getInt("port"));
p2p.setSoTimeout(3);
//p2p.setSoTimeout(3);
String output = JSONValue.toJSONString(parse.findOfferJSON(item_id.intValue()));
p2p.getOutputStream().write(output.getBytes());
......@@ -108,22 +107,28 @@ public class ClientHandler extends Thread {
String p2p_response = "{}";
if((length_buff = input.read(buffer)) >= 0) {
p2p_response = new String(buffer).substring(0, length_buff);
System.out.println("balesan server: " + p2p_response);
if (parse.parseJSON(p2p_response, "status").equals("ok")) {
JSONObject arrayObj = new JSONObject(p2p_response);
offerList.put(arrayObj.getJSONArray("offers"));
JSONArray p2p_offers = arrayObj.getJSONArray("offers");
for(int j=0;j<p2p_offers.length();j++){
offerList.put(p2p_offers.getJSONArray(j));
}
}
}
System.out.println(offerList);
}
}
System.out.println("keluar loop");
String localSearch = handler.sendFindResponse(response);
JSONObject resultlocal = new JSONObject(localSearch);
JSONArray apa[] = new JSONArray[offerList.length()];
for(int i=0; i<offerList.length(); i++) {
apa[i] = offerList.getJSONArray(i);
}
for(int i=0; i<offerList.length(); i++) {
resultlocal.put("offers", apa[i]);
//resultlocal.put("offers", apa[i]);
resultlocal.append("offers", apa[i]);
}
System.out.println("hasil sendfind: "+JSONValue.toJSONString(resultlocal));
out.writeUTF(JSONValue.toJSONString(resultlocal));
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment