Commit 79a8e39a authored by Rafi Ramadhan's avatar Rafi Ramadhan
Browse files

edit clientHandler

parent f674d6ce
...@@ -13,6 +13,7 @@ import java.net.ServerSocket; ...@@ -13,6 +13,7 @@ import java.net.ServerSocket;
import java.net.Socket; import java.net.Socket;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.json.simple.parser.ParseException;
/** /**
* *
...@@ -30,13 +31,58 @@ public class ClientHandler extends Thread { ...@@ -30,13 +31,58 @@ public class ClientHandler extends Thread {
public void run() { public void run() {
String response; String response;
JSONParse parse = new JSONParse(); JSONParse parse = new JSONParse();
MethodHandler handler = new MethodHandler();
while(true) { while(true) {
try { try {
DataInputStream in = new DataInputStream(socketListener.getInputStream()); DataInputStream in = new DataInputStream(socketListener.getInputStream());
response = in.readUTF(); response = in.readUTF();
System.out.println(response); System.out.println(response);
DataOutputStream out = new DataOutputStream(socketListener.getOutputStream()); DataOutputStream out = new DataOutputStream(socketListener.getOutputStream());
out.writeUTF("Thank you for connecting to " + socketListener.getLocalSocketAddress() + "\nGoodbye!");
if(parse.parseJSON(response, "method").equals("login")) {
out.writeUTF(handler.Login(response));
}
else if(parse.parseJSON(response, "method").equals("signup")) {
out.writeUTF(handler.Signup(response));
}
else if(parse.parseJSON(response, "method").equals("inventory")) {
out.writeUTF(handler.Inventory(response));
}
else if(parse.parseJSON(response, "method").equals("mixitem")) {
out.writeUTF(handler.MixItem(response));
}
else if(parse.parseJSON(response, "method").equals("map")) {
out.writeUTF(handler.Map(response));
}
else if(parse.parseJSON(response, "method").equals("move")) {
out.writeUTF(handler.Move(response));
}
else if(parse.parseJSON(response, "method").equals("field")) {
out.writeUTF(handler.Field(response));
}
else if(parse.parseJSON(response, "method").equals("offer")) {
out.writeUTF(handler.Offer(response));
}
else if(parse.parseJSON(response, "method").equals("tradebox")) {
out.writeUTF(handler.TradeBox(response));
}
else if(parse.parseJSON(response, "method").equals("sendfind")) {
out.writeUTF(handler.sendFind(response));
}
else if(parse.parseJSON(response, "method").equals("findoffer")) {
out.writeUTF(handler.sendFind(response));
}
else if(parse.parseJSON(response, "method").equals("sendaccept")) {
out.writeUTF(handler.sendFind(response));
}
else if(parse.parseJSON(response, "method").equals("accept")) {
out.writeUTF(handler.sendFind(response));
}
else {
out.writeUTF("Thank you for connecting to "
+ socketListener.getLocalSocketAddress() + "\nGoodbye!");
}
} catch (IOException ex) { } catch (IOException ex) {
Logger.getLogger(ClientHandler.class.getName()).log(Level.SEVERE, null, ex); Logger.getLogger(ClientHandler.class.getName()).log(Level.SEVERE, null, ex);
try { try {
...@@ -44,6 +90,8 @@ public class ClientHandler extends Thread { ...@@ -44,6 +90,8 @@ public class ClientHandler extends Thread {
} catch (IOException ex1) { } catch (IOException ex1) {
Logger.getLogger(ClientHandler.class.getName()).log(Level.SEVERE, null, ex1); Logger.getLogger(ClientHandler.class.getName()).log(Level.SEVERE, null, ex1);
} }
} catch (ParseException ex) {
Logger.getLogger(ClientHandler.class.getName()).log(Level.SEVERE, null, ex);
} }
} }
} }
......
...@@ -34,9 +34,6 @@ public class Server extends Thread { ...@@ -34,9 +34,6 @@ public class Server extends Thread {
public void run() public void run()
{ {
String response;
JSONParse parse = new JSONParse();
String response; String response;
JSONParse parse = new JSONParse(); JSONParse parse = new JSONParse();
MethodHandler handler = new MethodHandler(); MethodHandler handler = new MethodHandler();
...@@ -60,9 +57,6 @@ public class Server extends Thread { ...@@ -60,9 +57,6 @@ public class Server extends Thread {
new DataOutputStream(server.getOutputStream()); new DataOutputStream(server.getOutputStream());
if(parse.parseJSON(response, "method").equals("login")) { if(parse.parseJSON(response, "method").equals("login")) {
out.writeUTF(Login(response));
}
out.writeUTF(handler.Login(response)); out.writeUTF(handler.Login(response));
} }
else if(parse.parseJSON(response, "method").equals("signup")) { else if(parse.parseJSON(response, "method").equals("signup")) {
......
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