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

added serverList

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