Commit 1d207214 authored by Rakhmatullah Yoga Sutrisna's avatar Rakhmatullah Yoga Sutrisna
Browse files

tambah method buat deteksi ip address yg dipakai

parent 84503872
......@@ -9,6 +9,7 @@ package grandquestserver;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.logging.Level;
......@@ -23,7 +24,7 @@ public class ClientHandler extends Thread {
private Socket socketListener;
public ClientHandler(ServerSocket sock) throws IOException {
System.out.println("Waiting for client on port " + sock.getLocalPort() + "...");
System.out.println("Waiting for client on " + InetAddress.getLocalHost().getHostAddress()+ ":" + sock.getLocalPort() + "...");
socketListener = sock.accept();
System.out.println("Just connected to " + socketListener.getRemoteSocketAddress());
}
......@@ -38,51 +39,51 @@ public class ClientHandler extends Thread {
response = in.readUTF();
System.out.println(response);
DataOutputStream out = new DataOutputStream(socketListener.getOutputStream());
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!");
}
switch (parse.parseJSON(response, "method")) {
case "login":
out.writeUTF(handler.Login(response));
break;
case "signup":
out.writeUTF(handler.Signup(response));
break;
case "inventory":
out.writeUTF(handler.Inventory(response));
break;
case "mixitem":
out.writeUTF(handler.MixItem(response));
break;
case "map":
out.writeUTF(handler.Map(response));
break;
case "move":
out.writeUTF(handler.Move(response));
break;
case "field":
out.writeUTF(handler.Field(response));
break;
case "offer":
out.writeUTF(handler.Offer(response));
break;
case "tradebox":
out.writeUTF(handler.TradeBox(response));
break;
case "sendfind":
out.writeUTF(handler.sendFind(response));
break;
case "findoffer":
out.writeUTF(handler.sendFind(response));
break;
case "sendaccept":
out.writeUTF(handler.sendFind(response));
break;
case "accept":
out.writeUTF(handler.sendFind(response));
break;
default:
out.writeUTF("Thank you for connecting to "
+ socketListener.getLocalSocketAddress() + "\nGoodbye!");
break;
}
} catch (IOException ex) {
Logger.getLogger(ClientHandler.class.getName()).log(Level.SEVERE, null, ex);
try {
......
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