Commit 146cdc31 authored by Stephen's avatar Stephen
Browse files

Updated

parent d598baae
compile.on.save=true
user.properties.file=C:\\Users\\user\\AppData\\Roaming\\NetBeans\\8.0\\build.properties
user.properties.file=C:\\Users\\Stephen\\AppData\\Roaming\\NetBeans\\8.0.2\\build.properties
......@@ -802,11 +802,11 @@ public class TCPClient {
response = client.offer(client.token, 2, 1, 7, 3);
System.out.println(response.toString());
// response = client.sendFind(client.token, 2);
// System.out.println(response.toString());
response = client.findoffer(2);
response = client.sendFind(client.token, 2);
System.out.println(response.toString());
// response = client.findoffer(2);
// System.out.println(response.toString());
}
}
compile.on.save=true
user.properties.file=C:\\Users\\user\\AppData\\Roaming\\NetBeans\\8.0\\build.properties
user.properties.file=C:\\Users\\Stephen\\AppData\\Roaming\\NetBeans\\8.0.2\\build.properties
......@@ -618,7 +618,8 @@ public class MySQLAccess {
JSONArray offers = new JSONArray();
try {
preparedStatement = connect.prepareStatement("SELECT * FROM offer WHERE "
+ "offered_item=" + id_item + ";");
+ "offered_item=" + id_item + " AND "
+ "id_user=0;");
resultSet = preparedStatement.executeQuery();
while(resultSet.next()) {
......
......@@ -39,7 +39,7 @@ public class TCPServer implements Runnable {
serverPort = 6789;
serverClientSocket = new ServerSocket(serverPort);
servers = new ArrayList<Host>();
thisIP = "167.205.34.209";
thisIP = "167.205.71.56";
sql = new MySQLAccess();
}
......@@ -273,9 +273,15 @@ public class TCPServer implements Runnable {
public boolean moreThan5Minutes(String d1, String d2) {
boolean more = false;
String[] d1split = d1.split(":");
String[] d2split = d2.split(":");
int totalSec1 = Integer.parseInt(d1split[0])*3600 + Integer.parseInt(d1split[1])*60 + Integer.parseInt(d1split[2]);
int totalSec2 = Integer.parseInt(d2split[0])*3600 + Integer.parseInt(d2split[1])*60 + Integer.parseInt(d2split[2]);
if((totalSec1 - totalSec2) > 300) {
more = true;
}
return more;
}
......@@ -292,7 +298,7 @@ public class TCPServer implements Runnable {
findOfferTime = dateFormat.format(date);
}
if(firsttime || moreThan5Minutes(findOfferTime, currTime)) {
if(firsttime || moreThan5Minutes(currTime, findOfferTime)) {
JSONObject responseJSON = new JSONObject();
responseJSON.put("status", "ok");
JSONArray offers = new JSONArray();
......@@ -385,7 +391,7 @@ public class TCPServer implements Runnable {
}
}
public boolean isJSONValid(String test) {
public static boolean isJSONValid(String test) {
try {
new JSONObject(test);
} catch (JSONException ex) {
......@@ -422,7 +428,7 @@ public class TCPServer implements Runnable {
System.out.println("Received: " + server.clientRequest + "aaaaaaa");
if(!server.clientRequest.equalsIgnoreCase("") && server.isJSONValid(server.clientRequest)) {
if(!server.clientRequest.equalsIgnoreCase("") && isJSONValid(server.clientRequest)) {
// Mementuk JSON Object dari request client
JSONObject clientObject = new JSONObject(server.clientRequest);
String method = clientObject.getString("method");
......
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