Commit b1bea4ea authored by adwisatya's avatar adwisatya
Browse files

Revisi getIP()

parent acf9f982
......@@ -23,7 +23,7 @@ user.properties.file=C:\\Users\\adwisatya\\AppData\\Roaming\\NetBeans\\8.0.2\\bu
<<<<<<< HEAD
user.properties.file=C:\\Users\\Muldani\\AppData\\Roaming\\NetBeans\\8.0\\build.properties
=======
user.properties.file=C:\\Users\\Muldani\\AppData\\Roaming\\NetBeans\\8.0\\build.properties
user.properties.file=C:\\Users\\adwisatya\\AppData\\Roaming\\NetBeans\\8.0.2\\build.properties
>>>>>>> 43edd7f388dc28ed09074436ded7167fffce2bcf
>>>>>>> 08b39e9ffc058e8856fd1186a9d3fbe46d951054
>>>>>>> 7535768837b115ec28ff939840e034428f76d0e4
......
{"name" : "Bandar Behari","width" : 4,"height" : 4,"map" :[["R13", "R13", "R13", "R13"],["R13", "R13", "R14", "R14"],["R13", "R14", "R14", "R14"],["R13", "R14", "R14", "R14"]]}
......@@ -22,7 +22,7 @@ user.properties.file=C:\\Users\\adwisatya\\AppData\\Roaming\\NetBeans\\8.0.2\\bu
<<<<<<< HEAD
user.properties.file=C:\\Users\\Muldani\\AppData\\Roaming\\NetBeans\\8.0\\build.properties
=======
user.properties.file=C:\\Users\\Muldani\\AppData\\Roaming\\NetBeans\\8.0\\build.properties
user.properties.file=C:\\Users\\adwisatya\\AppData\\Roaming\\NetBeans\\8.0.2\\build.properties
>>>>>>> 43edd7f388dc28ed09074436ded7167fffce2bcf
>>>>>>> 08b39e9ffc058e8856fd1186a9d3fbe46d951054
>>>>>>> 7535768837b115ec28ff939840e034428f76d0e4
......
{"name" : "Bandar Behari","width" : 4,"height" : 4,"map" :[["R13", "R13", "R13", "R13"],["R13", "R13", "R14", "R14"],["R13", "R14", "R14", "R14"],["R13", "R14", "R14", "R14"]]}
......@@ -177,7 +177,6 @@ public class Client extends Thread{
public void cmdJoin() throws IOException, JSONException{
String response = "";
Socket miniSocket = new Socket(URL,defPort);
ArrayList<String> tmpServer = new ArrayList<String>();
JSONObject obj = new JSONObject();
obj.put("method", "join");
obj.put("ip", getIP());
......@@ -591,29 +590,35 @@ public class Client extends Thread{
return pass;
}
public String getIP(){
String myIP = "";
String ip;
// String myIP = "";
// String ip;
// try {
// Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
// while (interfaces.hasMoreElements()) {
// NetworkInterface iface = interfaces.nextElement();
// // filters out 127.0.0.1 and inactive interfaces
// if (iface.isLoopback() || !iface.isUp())
// continue;
//
// Enumeration<InetAddress> addresses = iface.getInetAddresses();
// while(addresses.hasMoreElements()) {
// InetAddress addr = addresses.nextElement();
// ip = addr.getHostAddress();
// if(ip.contains("167.205.")){
// myIP = ip;
// }
// }
// }
// } catch (SocketException e) {
// throw new RuntimeException(e);
// }
// return myIP;
String addr = "";
try {
Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
while (interfaces.hasMoreElements()) {
NetworkInterface iface = interfaces.nextElement();
// filters out 127.0.0.1 and inactive interfaces
if (iface.isLoopback() || !iface.isUp())
continue;
Enumeration<InetAddress> addresses = iface.getInetAddresses();
while(addresses.hasMoreElements()) {
InetAddress addr = addresses.nextElement();
ip = addr.getHostAddress();
if(ip.contains("167.205.")){
myIP = ip;
}
}
}
} catch (SocketException e) {
throw new RuntimeException(e);
addr = InetAddress.getLocalHost().getHostAddress();
} catch (UnknownHostException ex) {
Logger.getLogger(Client.class.getName()).log(Level.SEVERE, null, ex);
}
return myIP;
return addr;
}
}
......@@ -46,7 +46,7 @@ public class TCPServer {
ArrayList<String> tmpServer = new ArrayList<String>();
JSONObject obj = new JSONObject();
obj.put("method", "join");
obj.put("ip", "167.205.34.195");
obj.put("ip", InetAddress.getLocalHost().getHostAddress());
obj.put("port", new Integer(myPort));
PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(miniSocket.getOutputStream())));
......@@ -58,16 +58,5 @@ public class TCPServer {
response = org.apache.commons.io.IOUtils.toString(in);
in.close();
System.out.println(response);
//
// JSONObject objResponse = new JSONObject(response);
// if(isJSONValid(objResponse.toString())){
// JSONArray objArr = new JSONArray(obj.getJSONArray("value"));
// for(int i = 0; i<objArr.length();i++){
// objArr.getJSONObject(i).get("ip");
// objArr.getJSONObject(i).get("port");
// tmpServer.add(objArr.toString());
// }
// }
}
}
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