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

sendfind solved v.2

parent f3244eda
......@@ -51,7 +51,7 @@ public class ClientHandler extends Thread {
try {
DataInputStream in = new DataInputStream(socketListener.getInputStream());
response = in.readUTF();
System.out.println(response);
System.out.println(socketListener.getRemoteSocketAddress()+": "+response);
DataOutputStream out = new DataOutputStream(socketListener.getOutputStream());
switch (parse.parseJSON(response, "method")) {
case "login":
......@@ -97,7 +97,6 @@ public class ClientHandler extends Thread {
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);
String output = JSONValue.toJSONString(parse.findOfferJSON(item_id.intValue()));
p2p.getOutputStream().write(output.getBytes());
......@@ -107,7 +106,6 @@ 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);
JSONArray p2p_offers = arrayObj.getJSONArray("offers");
......@@ -116,25 +114,22 @@ public class ClientHandler extends Thread {
}
}
}
System.out.println(offerList);
}
}
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.append("offers", apa[i]);
}
System.out.println("hasil sendfind: "+JSONValue.toJSONString(resultlocal));
out.writeUTF(JSONValue.toJSONString(resultlocal));
break;
case "findoffer":
out.writeUTF(handler.findOffer(response));
out.writeUTF(handler.sendFindResponse(response));
break;
case "sendaccept":
out.writeUTF(handler.sendAccept(response));
......
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