Commit a90ff3fc authored by Junita Sinambela's avatar Junita Sinambela
Browse files

ubah dikit 1

parent 8bd39885
......@@ -61,21 +61,21 @@ public class Server {
Socket trackerSocket = null;
try {
trackerSocket = new Socket("167.205.32.46", 8000);
ServerLogger.log("SERVER_THREAD", "Sending request join");
ServerLogger.log("MAIN_THREAD", "Sending request join");
while(!joiningTracker(trackerSocket)){
ServerLogger.log("SERVER_THREAD", "Sending request join (again)");
ServerLogger.log("MAIN_THREAD", "Sending request join (again)");
}
ServerSocket welcomeSocket = null;
Socket clientSocket = null;
welcomeSocket = new ServerSocket(6789);
ServerLogger.log("SERVER_THREAD", "Start listening to new connection");
ServerLogger.log("MAIN_THREAD", "Start listening to new connection");
while(true){
clientSocket = welcomeSocket.accept();
ServerLogger.log("SERVER_THREAD", "New connection accepted");
ServerLogger.log("MAIN_THREAD", "New connection accepted");
new Thread(new ClientHandler(clientSocket)).start();
}
} catch (IOException | JSONException ex) {
ServerLogger.log("SERVER_THREAD", "Failed");
ServerLogger.log("MAIN_THREAD", "Failed");
System.out.println(ex.getMessage());
ex.printStackTrace();
}
......
......@@ -606,6 +606,11 @@ public class Message {
JSONObject jsonAllOffers;
JSONObject jsonObj;
try{
jsonObj = new JSONObject();
jsonObj.put("method", "findoffer");
jsonObj.put("item", itemId);
response = ServerHandler.broadcast(jsonObj.toString());
//buat json b
ArrayList<ArrayList<Object>> allOffers = Database.getTradebox(token,itemId);
jsonAllOffers = new JSONObject();
if(allOffers != null)
......@@ -616,11 +621,7 @@ public class Message {
}
else
{
jsonObj = new JSONObject();
jsonObj.put("method", "findoffer");
jsonObj.put("item", itemId);
response = ServerHandler.broadcast(jsonObj.toString());
//tangani kalau mau dimasukin ke database
response = error();
}
}
......@@ -633,48 +634,53 @@ public class Message {
return response;
}
//offer
//tradebox
//sendfind
/**
* Send find offer to another server. Untuk menemukan semua offer yang tersedia dari semua server
* @param item
* Accept offer sesuai dengan item id yang diinginkan. Dikirim oleh client.
* @param token
* @param offer_token
* @return
*/
public static String sendFindOffer(int item) //12
public static String sendAccept(String token, String offer_token) //String token, int itemId) //11
{
JSONObject jsonObj = new JSONObject();
String response = null;
if(log)
{
System.out.println(response);
}
return response;
}
public static String sendAccept() //String token, int itemId) //11
/**
* Fungsi untuk catch method find offer dari server lain
* @param itemIdx
* @return
*/
public static String findOffer(int itemIdx) //12
{
String response = null;
if(log)
System.out.println(response);
String response;
JSONObject jsonObj = new JSONObject();
try
{
jsonObj.put("status", "ok");
jsonObj.put("offers", Database.getTradebox(itemIdx));
response = jsonObj.toString();
}catch(JSONException ex)
{
System.out.println("getFindOffer() Error: " + jsonObj.toString());
response = error();
}
return response;
}
/**
* Fungsi untuk catch method find offer dari server lain
* @param itemIdx
* @param offer_token
* @return
*/
public static String getFindOffer(int itemIdx) //12
public static String accept(String offer_token) //12
{
String response;
JSONObject jsonObj = new JSONObject();
try
{
jsonObj.put("status", "ok");
jsonObj.put("offers", Database.getTradebox(itemIdx));
Database.changeLocalTradeboxToFalse(offer_token);
response = jsonObj.toString();
}catch(JSONException ex)
{
......
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