Commit 4425b3f1 authored by Susanti Gojali's avatar Susanti Gojali
Browse files

merge conflict

parents da414405 9b3bab9e
compile.on.save=true
<<<<<<< HEAD
<<<<<<< HEAD
user.properties.file=C:\\Users\\user\\AppData\\Roaming\\NetBeans\\8.0\\build.properties
=======
<<<<<<< HEAD
......@@ -8,3 +9,7 @@ user.properties.file=C:\\Users\\user\\AppData\\Roaming\\NetBeans\\8.0\\build.pro
>>>>>>> 2e2ad538abfe623e38cc24be02c48f5ad2ee0768
user.properties.file=C:\\Users\\susanti_2\\AppData\\Roaming\\NetBeans\\8.0.2\\build.properties
>>>>>>> 43e41c8c08f84039568ca701a584f38f9911e548
=======
user.properties.file=C:\\Users\\Stephen\\AppData\\Roaming\\NetBeans\\8.0.2\\build.properties
>>>>>>> 9b3bab9e9eefddca873933beff1cff411b869149
......@@ -3,8 +3,18 @@
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
<group>
<<<<<<< HEAD
<file>file:/C:/Users/susanti_2/Documents/ITB/IF/netbeans/IF3230-Tugas-Besar-Sister-2015/src/client/src/tcpclient/MainPage.java</file>
<file>file:/C:/Users/susanti_2/Documents/ITB/IF/netbeans/IF3230-Tugas-Besar-Sister-2015/src/client/src/tcpclient/TCPClient.java</file>
=======
<<<<<<< HEAD
<file>file:/E:/semester%206/Sistem%20Paralel%20dan%20Terdistribusi/SISTER/IF3230-Tugas-Besar-Sister-2015/src/client/src/tcpclient/TCPClient.java</file>
<file>file:/E:/semester%206/Sistem%20Paralel%20dan%20Terdistribusi/SISTER/IF3230-Tugas-Besar-Sister-2015/src/client/src/tcpclient/MainPage.java</file>
=======
<file>file:/C:/Users/Stephen/Documents/NetBeansProjects/TubesSister/src/client/src/tcpclient/TCPClient.java</file>
<file>file:/C:/Users/Stephen/Documents/NetBeansProjects/TubesSister/src/client/src/tcpclient/MainPage.java</file>
>>>>>>> 6ee3636e215ce68e8e6c04438b47fa355e8396b2
>>>>>>> 9b3bab9e9eefddca873933beff1cff411b869149
</group>
</open-files>
</project-private>
This diff is collapsed.
This diff is collapsed.
......@@ -9,7 +9,7 @@ public class MapTableModel extends AbstractTableModel{
private Object[][] data;
private int dimX;
private int dimY;
public MapTableModel() {
dimX=0;
dimY=0;
......@@ -51,6 +51,6 @@ public class MapTableModel extends AbstractTableModel{
public Class<?> getColumnClass(int column) {
return ImageIcon.class;
}
}
......@@ -335,6 +335,7 @@ public class TCPClient {
} catch (IOException ex) {
Logger.getLogger(TCPClient.class.getName()).log(Level.SEVERE, null, ex);
throw new Exception("outtoserver field exception");
}
//ambil balasan server
......@@ -358,6 +359,7 @@ public class TCPClient {
} catch (IOException ex) {
Logger.getLogger(TCPClient.class.getName()).log(Level.SEVERE, null, ex);
throw new Exception("outtoserver canceloffer exception");
}
//ambil balasan server
......@@ -368,7 +370,6 @@ public class TCPClient {
return responseJSON;
}
public static void main(String argv[]) throws Exception
{
TCPClient client = new TCPClient("localhost", 6789);
......@@ -495,9 +496,4 @@ public class TCPClient {
System.out.println(response.toString());
}
//
}
<<<<<<< HEAD
#Sun, 19 Apr 2015 14:13:30 +0700
C\:\\Users\\susanti_2\\Documents\\ITB\\IF\\netbeans\\IF3230-Tugas-Besar-Sister-2015\\src\\server=
=======
#Sun, 19 Apr 2015 16:30:46 +0700
C\:\\Users\\Stephen\\Documents\\NetBeansProjects\\TubesSister\\src\\server=
>>>>>>> 9b3bab9e9eefddca873933beff1cff411b869149
compile.on.save=true
<<<<<<< HEAD
user.properties.file=C:\\Users\\user\\AppData\\Roaming\\NetBeans\\8.0\\build.properties
=======
>>>>>>> 9b3bab9e9eefddca873933beff1cff411b869149
do.depend=false
do.jar=true
javac.debug=true
javadoc.preview=true
<<<<<<< HEAD
user.properties.file=C:\\Users\\user\\AppData\\Roaming\\NetBeans\\8.0\\build.properties
user.properties.file=C:\\Users\\susanti_2\\AppData\\Roaming\\NetBeans\\8.0.2\\build.properties
=======
user.properties.file=C:\\Users\\Stephen\\AppData\\Roaming\\NetBeans\\8.0.2\\build.properties
>>>>>>> 9b3bab9e9eefddca873933beff1cff411b869149
......@@ -3,7 +3,12 @@
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
<group>
<<<<<<< HEAD
<file>file:/C:/Users/susanti_2/Documents/ITB/IF/netbeans/IF3230-Tugas-Besar-Sister-2015/src/server/src/tcpserver/TCPServer.java</file>
=======
<file>file:/C:/Users/Stephen/Documents/NetBeansProjects/TubesSister/src/server/src/tcpserver/TCPServer.java</file>
<file>file:/C:/Users/Stephen/Documents/NetBeansProjects/TubesSister/src/server/src/tcpserver/MySQLAccess.java</file>
>>>>>>> 9b3bab9e9eefddca873933beff1cff411b869149
</group>
</open-files>
</project-private>
......@@ -33,13 +33,15 @@ file.reference.guava-11.0.2.jar=lib/guava-11.0.2.jar
file.reference.java-json.jar=lib\\java-json.jar
file.reference.json-simple-1.1.1.jar=lib/json-simple-1.1.1.jar
file.reference.mysql-connector-java-5.1.30-bin.jar=lib\\mysql-connector-java-5.1.30-bin.jar
file.reference.p2psockets-core-1.1.2.jar=lib\\p2psockets-core-1.1.2.jar
includes=**
jar.compress=false
javac.classpath=\
${file.reference.java-json.jar}:\
${file.reference.mysql-connector-java-5.1.30-bin.jar}:\
${file.reference.json-simple-1.1.1.jar}:\
${file.reference.guava-11.0.2.jar}
${file.reference.guava-11.0.2.jar}:\
${file.reference.p2psockets-core-1.1.2.jar}
# Space-separated list of extra javac options
javac.compilerargs=
javac.deprecation=false
......
package tcpserver;
public class Host {
public String ipAddress;
public int port;
public Host(String ipAddress, int port) {
this.ipAddress = ipAddress;
this.port = port;
}
public void print() {
System.out.println("ip: " + ipAddress + ", port: " + port);
}
}
......@@ -3,25 +3,78 @@ package tcpserver;
import java.io.*;
import java.net.*;
import com.google.common.io.CharStreams;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import jdk.nashorn.internal.parser.JSONParser;
import org.json.*;
public class TCPServer {
public ServerSocket serverSocket;
public Socket connectionSocket;
public class TCPServer implements Runnable {
public ServerSocket serverClientSocket;
public ServerSocket serverTrackerSocket;
public Socket clientSocket;
public Socket trackerSocket;
public MySQLAccess sql;
public String request;
public String clientRequest;
public String trackerRequest;
public String token;
public int userID;
public int width;
public int height;
public static String[][] map;
public List<Host> servers;
public TCPServer(int port) throws IOException {
System.out.println("Server running! Waiting for connection...");
serverSocket = new ServerSocket(port);
connectionSocket = serverSocket.accept();
public TCPServer(int port) throws IOException, JSONException {
System.out.println("Server running!");
serverClientSocket = new ServerSocket(port);
servers = new ArrayList<Host>();
// Test join tracker
// join(InetAddress.getLocalHost().getHostAddress(), 6790);
sql = new MySQLAccess();
}
public void printAllServers() {
System.out.println("Server yang terhubung :");
for(Host server : servers) {
server.print();
}
}
public void join(String ip, int port) throws JSONException, UnknownHostException, IOException {
JSONObject joinRequest = new JSONObject();
joinRequest.put("method", "join");
joinRequest.put("ip", ip);
joinRequest.put("port", port);
boolean joined = false;
do {
trackerSocket = new Socket("167.205.32.46", 8000);
DataOutputStream outToServer;
try {
outToServer = new DataOutputStream(trackerSocket.getOutputStream());
outToServer.writeBytes(joinRequest.toString());
} catch (IOException ex) {
ex.printStackTrace();
}
BufferedReader inFromServer = new BufferedReader(new InputStreamReader(trackerSocket.getInputStream()));
String response = inFromServer.readLine();
JSONObject joinResponse = new JSONObject(response);
if(joinResponse.getString("status").equalsIgnoreCase("ok")) {
System.out.println("Success joining tracker!");
JSONArray serverarray = joinResponse.getJSONArray("value");
for (int i=0; i<serverarray.length(); i++) {
JSONObject server = new JSONObject(serverarray.get(i).toString());
Host host = new Host(server.getString("ip"), server.getInt("port"));
servers.add(host);
}
printAllServers();
joined=true;
}
} while(!joined);
}
public JSONObject signup(JSONObject clientObject) throws JSONException {
......@@ -137,25 +190,82 @@ public class TCPServer {
}
}
public JSONObject serverstatus(JSONObject clientObject) throws JSONException {
JSONObject responseJSON = new JSONObject();
responseJSON.put("status", "ok");
servers.clear();
JSONArray serverarray = clientObject.getJSONArray("server");
for (int i=0; i<serverarray.length(); i++) {
JSONObject server = new JSONObject(serverarray.get(i).toString());
Host host = new Host(server.getString("ip"), server.getInt("port"));
servers.add(host);
}
printAllServers();
return responseJSON;
}
public void run() {
while(true) {
int port = 6790;
try {
while(true) {
// Menunggu koneksi dari tracker
System.out.println("Waiting for tracker to connect..");
serverTrackerSocket = new ServerSocket(port);
trackerSocket = serverTrackerSocket.accept();
System.out.println("Tracker connected!");
// Membaca request dari client
BufferedReader inFromClient =new BufferedReader(new InputStreamReader(trackerSocket.getInputStream()));
DataOutputStream outToClient = new DataOutputStream(trackerSocket.getOutputStream());
trackerRequest = inFromClient.readLine();
// Cek apakah ping dari tracker
if(!trackerRequest.equalsIgnoreCase("")) {
JSONObject clientObject = new JSONObject(trackerRequest);
String method = clientObject.getString("method");
if(method.equalsIgnoreCase("serverStatus")) {
JSONObject responseJSON = serverstatus(clientObject);
System.out.println(responseJSON.toString());
outToClient.writeBytes(responseJSON.toString());
}
}
}
} catch(Exception e) {
e.printStackTrace();
}
}
}
public static void main(String[] args) throws Exception {
int port = 6789;
TCPServer server = new TCPServer(port);
System.out.println("User connected to " + server.serverSocket.getLocalSocketAddress() + ", " + server.connectionSocket.getLocalSocketAddress());
// Starts a thread that listens to tracker
Thread trackerListener =new Thread(server);
trackerListener.start();
System.out.println("Waiting for client to connect..");
server.clientSocket = server.serverClientSocket.accept();
System.out.println("User connected to " + server.serverClientSocket.getLocalSocketAddress() + ", " + server.clientSocket.getLocalSocketAddress());
while(true)
{
// Membaca request dari client
BufferedReader inFromClient =new BufferedReader(new InputStreamReader(server.connectionSocket.getInputStream()));
DataOutputStream outToClient = new DataOutputStream(server.connectionSocket.getOutputStream());
server.request = inFromClient.readLine();
BufferedReader inFromClient =new BufferedReader(new InputStreamReader(server.clientSocket.getInputStream()));
DataOutputStream outToClient = new DataOutputStream(server.clientSocket.getOutputStream());
server.clientRequest = inFromClient.readLine();
System.out.println("Received: " + server.request);
System.out.println("Received: " + server.clientRequest);
// Mementuk JSON Object dari request client
JSONObject clientObject = new JSONObject(server.request);
JSONObject clientObject = new JSONObject(server.clientRequest);
String method = clientObject.getString("method");
if(method.equalsIgnoreCase("signup")) { // Jika method request adalah "signup"
JSONObject responseJSON = server.signup(clientObject);
System.out.println(responseJSON.toString());
......@@ -197,6 +307,10 @@ public class TCPServer {
JSONObject responseJSON = server.offer(clientObject);
System.out.println(responseJSON.toString());
outToClient.writeBytes(responseJSON.toString() + "\n");
} else if(method.equalsIgnoreCase("canceloffer")) {
JSONObject responseJSON = server.canceloffer(clientObject);
System.out.println(responseJSON.toString());
outToClient.writeBytes(responseJSON.toString() + "\n");
}
else if(method.equalsIgnoreCase("canceloffer")) {
JSONObject responseJSON = server.canceloffer(clientObject);
......
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