Commit 1e104926 authored by Jonathan Sudibya's avatar Jonathan Sudibya
Browse files

added serverList

parent 5d38d8f9
...@@ -14,7 +14,10 @@ import java.util.Map; ...@@ -14,7 +14,10 @@ import java.util.Map;
import java.util.Vector; import java.util.Vector;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
/* /*
* To change this license header, choose License Headers in Project Properties. * To change this license header, choose License Headers in Project Properties.
...@@ -37,6 +40,7 @@ public class ConnectionHandler implements Runnable { ...@@ -37,6 +40,7 @@ public class ConnectionHandler implements Runnable {
private int serverSocket; private int serverSocket;
public static Map<String,String> tokenMap; public static Map<String,String> tokenMap;
public static JSONArray serverList;
public ConnectionHandler(){ public ConnectionHandler(){
threadName = "Connection-Handler"; threadName = "Connection-Handler";
...@@ -89,10 +93,11 @@ public class ConnectionHandler implements Runnable { ...@@ -89,10 +93,11 @@ public class ConnectionHandler implements Runnable {
private boolean connectTracker() private boolean connectTracker()
{ {
boolean ret; boolean ret = false;
try { try {
String sentence; String sentence;
String modifiedSentence; String modifiedSentence;
JSONParser parser = new JSONParser();
BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in)); BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in));
Socket newServer = new Socket("167.205.32.46", 8000); Socket newServer = new Socket("167.205.32.46", 8000);
DataOutputStream outToTracker = new DataOutputStream(newServer.getOutputStream()); DataOutputStream outToTracker = new DataOutputStream(newServer.getOutputStream());
...@@ -105,11 +110,15 @@ public class ConnectionHandler implements Runnable { ...@@ -105,11 +110,15 @@ public class ConnectionHandler implements Runnable {
outToTracker.write(sentence.getBytes(Charset.forName("UTF-8"))); outToTracker.write(sentence.getBytes(Charset.forName("UTF-8")));
modifiedSentence = inFromTracker.readLine(); modifiedSentence = inFromTracker.readLine();
System.out.println("FROM TRACKER: " + modifiedSentence); System.out.println("FROM TRACKER: " + modifiedSentence);
newServer.close(); Object obj = parser.parse(modifiedSentence);
JSONObject serverData = (JSONObject) obj;
serverList = (JSONArray) serverData.get("value");
ret = true; ret = true;
} catch (IOException ex) { } catch (IOException ex) {
ret = false; ret = false;
Logger.getLogger(ConnectionHandler.class.getName()).log(Level.SEVERE, null, ex); Logger.getLogger(ConnectionHandler.class.getName()).log(Level.SEVERE, null, ex);
} catch (ParseException ex) {
Logger.getLogger(ConnectionHandler.class.getName()).log(Level.SEVERE, null, ex);
} }
return ret; return ret;
} }
......
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