Commit 72e7361c authored by Rakhmatullah Yoga Sutrisna's avatar Rakhmatullah Yoga Sutrisna
Browse files

nyicil start contact tracker

parent 761076f6
......@@ -6,12 +6,14 @@
package grandquestserver;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.json.simple.parser.ParseException;
/**
*
......@@ -21,21 +23,38 @@ public class TrackerListener extends Thread {
private Socket trackListener;
private final String trackerAddress = "167.205.32.46";
private final int trackerPort = 8000;
private boolean ready;
public TrackerListener() throws IOException {
System.out.println("Connecting to tracker . . .");
trackListener = new Socket(trackerAddress, trackerPort);
System.out.println("Just connected to tracker!");
ready = false;
}
@Override
public void run() {
public void newServerRequest() throws ParseException {
try {
System.out.println("Connecting to tracker . . .");
Socket client = new Socket(trackerAddress, trackerPort);
System.out.println("Just connected to tracker!");
OutputStream outToServer = client.getOutputStream();
OutputStream outToServer = trackListener.getOutputStream();
DataOutputStream out = new DataOutputStream(outToServer);
JSONParse parser = new JSONParse();
out.writeUTF(trackerAddress);
DataInputStream in = new DataInputStream(trackListener.getInputStream());
String response = in.readUTF();
switch (parser.parseJSON(response, "status")) {
case "ok":
// nyimpen data semua server
ready = true;
break;
case "error":
break;
default:
break;
}
} catch (IOException ex) {
Logger.getLogger(TrackerListener.class.getName()).log(Level.SEVERE, null, ex);
}
}
@Override
public void run() {
}
}
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