Commit d06a654c authored by Hendro Triokta Brianto's avatar Hendro Triokta Brianto
Browse files

test server

parents 1985a04d ab35a18e
......@@ -3,6 +3,7 @@
<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:/F:/z~edo/Kuliah/Semester%206/IF3230%20Sistem%20Paralel%20dan%20Terdistribusi/Tugas%20Akhir/src/client/TheAlchemistClient/src/thealchemist/gui/AlcMixItem.java</file>
<file>file:/F:/z~edo/Kuliah/Semester%206/IF3230%20Sistem%20Paralel%20dan%20Terdistribusi/Tugas%20Akhir/src/client/TheAlchemistClient/src/thealchemist/gui/AlcLogon.java</file>
<file>file:/F:/z~edo/Kuliah/Semester%206/IF3230%20Sistem%20Paralel%20dan%20Terdistribusi/Tugas%20Akhir/src/client/TheAlchemistClient/src/thealchemist/gui/AlcMap.java</file>
......@@ -12,6 +13,19 @@
<file>file:/F:/z~edo/Kuliah/Semester%206/IF3230%20Sistem%20Paralel%20dan%20Terdistribusi/Tugas%20Akhir/src/client/TheAlchemistClient/src/thealchemist/gui/AlcItem.java</file>
<file>file:/F:/z~edo/Kuliah/Semester%206/IF3230%20Sistem%20Paralel%20dan%20Terdistribusi/Tugas%20Akhir/src/client/TheAlchemistClient/src/thealchemist/engine/Response.java</file>
<file>file:/F:/z~edo/Kuliah/Semester%206/IF3230%20Sistem%20Paralel%20dan%20Terdistribusi/Tugas%20Akhir/src/client/TheAlchemistClient/src/thealchemist/engine/Connection.java</file>
=======
<file>file:/C:/Users/adwisatya/Documents/Semester%206/Tugas/IF3230%20Sister/IF3230-Tugas-Besar-Sister-2015/src/client/TheAlchemistClient/src/thealchemist/gui/AlcOffer.java</file>
<file>file:/C:/Users/adwisatya/Documents/Semester%206/Tugas/IF3230%20Sister/IF3230-Tugas-Besar-Sister-2015/src/client/TheAlchemistClient/src/thealchemist/gui/AlcItem.java</file>
<file>file:/C:/Users/adwisatya/Documents/Semester%206/Tugas/IF3230%20Sister/IF3230-Tugas-Besar-Sister-2015/src/client/TheAlchemistClient/src/thealchemist/gui/AlcFindItem.java</file>
<file>file:/C:/Users/adwisatya/Documents/Semester%206/Tugas/IF3230%20Sister/IF3230-Tugas-Besar-Sister-2015/src/client/TheAlchemistClient/src/thealchemist/gui/AlcMap.java</file>
<file>file:/C:/Users/adwisatya/Documents/Semester%206/Tugas/IF3230%20Sister/IF3230-Tugas-Besar-Sister-2015/src/client/TheAlchemistClient/src/thealchemist/engine/Connection.java</file>
<file>file:/C:/Users/adwisatya/Documents/Semester%206/Tugas/IF3230%20Sister/IF3230-Tugas-Besar-Sister-2015/src/client/TheAlchemistClient/src/thealchemist/engine/Main.java</file>
<file>file:/C:/Users/adwisatya/Documents/Semester%206/Tugas/IF3230%20Sister/IF3230-Tugas-Besar-Sister-2015/src/client/TheAlchemistClient/src/thealchemist/gui/AlcTradeBox.java</file>
<file>file:/C:/Users/adwisatya/Documents/Semester%206/Tugas/IF3230%20Sister/IF3230-Tugas-Besar-Sister-2015/src/client/TheAlchemistClient/src/thealchemist/gui/AlcTradeItem.java</file>
<file>file:/C:/Users/adwisatya/Documents/Semester%206/Tugas/IF3230%20Sister/IF3230-Tugas-Besar-Sister-2015/src/client/TheAlchemistClient/src/thealchemist/gui/AlcLogon.java</file>
<file>file:/C:/Users/adwisatya/Documents/Semester%206/Tugas/IF3230%20Sister/IF3230-Tugas-Besar-Sister-2015/src/client/TheAlchemistClient/src/thealchemist/gui/AlcMixItem.java</file>
<file>file:/C:/Users/adwisatya/Documents/Semester%206/Tugas/IF3230%20Sister/IF3230-Tugas-Besar-Sister-2015/src/client/TheAlchemistClient/src/thealchemist/gui/ImagePanel.java</file>
>>>>>>> ab35a18e11b0fab1af378a1ddb185a0c486fc47b
</group>
</open-files>
</project-private>
......@@ -7,7 +7,9 @@ package thealchemist.engine;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
......@@ -30,7 +32,8 @@ public class Connection {
String request;
// private static String URL = "167.205.32.46";
// private static int defPort = 8025;
private static String URL = "192.168.0.107";
private static String URL = "localhost";
private static int defPort = 6789;
private String token = "kosong";
......@@ -39,17 +42,15 @@ public class Connection {
Socket miniSocket = new Socket(URL,defPort);
JSONObject obj = new JSONObject(JSON);
// obj.put("method", "join");
// obj.put("ip", "167.205.32.46");
// obj.put("port", new Integer(8000));
PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(miniSocket.getOutputStream())));
out.println(obj);
out.println();
out.flush();
BufferedReader in = new BufferedReader(new InputStreamReader(miniSocket.getInputStream()));
InputStream dataInputStream = new DataInputStream(miniSocket.getInputStream());
InputStreamReader inputStreamReader = new InputStreamReader(dataInputStream);
BufferedReader in = new BufferedReader(inputStreamReader);
response = in.readLine();
in.close();
......
......@@ -170,7 +170,7 @@ public class AlcLogon extends javax.swing.JFrame {
try {
try {
pass = new String(txtPassword.getPassword());
hasilRespon = connection.login(txtAccount.getText(), pass);
if(connection.JSONtoString("status", hasilRespon).equals("ok")){
JOptionPane.showMessageDialog(this,
......
#Sun, 26 Apr 2015 16:00:29 +0700
#Sun, 26 Apr 2015 20:27:08 +0700
F\:\\z~edo\\Kuliah\\Semester\ 6\\IF3230\ Sistem\ Paralel\ dan\ Terdistribusi\\Tugas\ Akhir\\src\\server=
C\:\\Users\\adwisatya\\Documents\\Semester\ 6\\Tugas\\IF3230\ Sister\\IF3230-Tugas-Besar-Sister-2015\\src\\server=
{"name" : "Bandar Behari","width" : 4,"height" : 4,"map" :[["R13", "R13", "R13", "R13"],["R13", "R13", "R14", "R14"],["R13", "R14", "R14", "R14"],["R13", "R14", "R14", "R14"]]}
......@@ -3,9 +3,16 @@
<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:/F:/z~edo/Kuliah/Semester%206/IF3230%20Sistem%20Paralel%20dan%20Terdistribusi/Tugas%20Akhir/src/server/src/thealchemist/Client.java</file>
<file>file:/F:/z~edo/Kuliah/Semester%206/IF3230%20Sistem%20Paralel%20dan%20Terdistribusi/Tugas%20Akhir/src/server/src/thealchemist/TCPServer.java</file>
<file>file:/F:/z~edo/Kuliah/Semester%206/IF3230%20Sistem%20Paralel%20dan%20Terdistribusi/Tugas%20Akhir/src/server/src/thealchemist/Database.java</file>
=======
<file>file:/C:/Users/adwisatya/Documents/Semester%206/Tugas/IF3230%20Sister/IF3230-Tugas-Besar-Sister-2015/src/server/src/folder/map.json</file>
<file>file:/C:/Users/adwisatya/Documents/Semester%206/Tugas/IF3230%20Sister/IF3230-Tugas-Besar-Sister-2015/src/server/src/thealchemist/Client.java</file>
<file>file:/C:/Users/adwisatya/Documents/Semester%206/Tugas/IF3230%20Sister/IF3230-Tugas-Besar-Sister-2015/src/server/src/thealchemist/Database.java</file>
<file>file:/C:/Users/adwisatya/Documents/Semester%206/Tugas/IF3230%20Sister/IF3230-Tugas-Besar-Sister-2015/src/server/src/thealchemist/TCPServer.java</file>
>>>>>>> ab35a18e11b0fab1af378a1ddb185a0c486fc47b
</group>
</open-files>
</project-private>
......@@ -7,11 +7,14 @@ package thealchemist;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.net.*;
import java.security.MessageDigest;
......@@ -39,17 +42,13 @@ public class Client extends Thread{
public static int defPort = 8000;
public static int dbPort = 8025;
public static int myPort = 6789;
private static int MAX_BUFFER = 1024;
/* Client attributes */
public String token;
public String tmpStr;
public String time;
public ArrayList<String> location = new ArrayList<String>(Arrays.asList("0", "0"));
NetworkInterface networkinterface = NetworkInterface.getByIndex(13);
//public int item;
// public int heigth;
// public int width;
// public String name;
// public String inventory;
public ArrayList<Integer> items;
public ArrayList<String> servers;
public String offers;
......@@ -60,29 +59,47 @@ public class Client extends Thread{
}
public void run(){
getIP();
//getIP();
/* Testing database */
clientSentence = "";
while(!clientSentence.equals("dead")){
char[] buffer = new char[MAX_BUFFER];
while(true){
try{
fromClient = new BufferedReader(new InputStreamReader(connectionSocket.getInputStream()));
toClient = new DataOutputStream(connectionSocket.getOutputStream());
clientSentence = fromClient.readLine();
toClient.writeBytes("Anda mengirimkan " + clientSentence + "\n");
checkCommand(clientSentence.toString());
fromClient.read(buffer);
clientSentence = new String(buffer);
checkCommand(clientSentence);
}catch(IOException e){
System.out.println(e);
try {
connectionSocket.close();
} catch (IOException ex) {
Logger.getLogger(Client.class.getName()).log(Level.SEVERE, null, ex);
ex.printStackTrace();
}
} catch (NoSuchAlgorithmException ex) {
try {
connectionSocket.close();
} catch (IOException ex1) {
ex1.printStackTrace();
Logger.getLogger(Client.class.getName()).log(Level.SEVERE, null, ex1);
}
Logger.getLogger(Client.class.getName()).log(Level.SEVERE, null, ex);
} catch (JSONException ex) {
try {
connectionSocket.close();
} catch (IOException ex1) {
Logger.getLogger(Client.class.getName()).log(Level.SEVERE, null, ex1);
}
Logger.getLogger(Client.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
public void sendToClient(String tmpStr) throws IOException{
new DataOutputStream(connectionSocket.getOutputStream()).writeBytes(tmpStr);
PrintStream out = new PrintStream(connectionSocket.getOutputStream());
out.print(tmpStr);
System.out.println(tmpStr);
}
public void checkCommand(String cmd) throws IOException, NoSuchAlgorithmException, JSONException {
cmdJoin();
......@@ -613,13 +630,11 @@ public class Client extends Thread{
}
public void loadMap(){
String filename = "map.json";
try {
JSONObject objMap = new JSONObject(new FileReader("folder/"+filename));
System.out.println(objMap.toString());
} catch (FileNotFoundException ex) {
System.out.println("gagal load");
Logger.getLogger(Client.class.getName()).log(Level.SEVERE, null, ex);
File f = new File("file.json");
if(f.exists()){
System.out.println("ada");
}else{
System.out.println("tidak ada");
}
}
}
......@@ -42,7 +42,6 @@ public class Database {
Logger.getLogger(Database.class.getName()).log(Level.SEVERE, null, ex);
}
rs = statement.executeUpdate();
System.out.println(rs);
statement.close();
conn.close();
}catch(SQLException e){
......
......@@ -26,18 +26,31 @@ import static thealchemist.Client.myPort;
public class TCPServer {
static int portNumber = 6789;
public static void main(String argv[]) throws Exception{
ServerSocket mainSocket;
// ServerSocket mainSocket ;
// mainSocket = new ServerSocket(portNumber);
// System.out.println("Start listening...");
// cmdJoin();
// while(!mainSocket.isClosed()){
// Socket connectionSocket = mainSocket.accept();
// if(connectionSocket != null){
// Client client = new Client(connectionSocket);
// client.start();
// }
// }
ServerSocket mainSocket ;
mainSocket = new ServerSocket(portNumber);
System.out.println("Start listening...");
cmdJoin();
while(true){
Socket connectionSocket = mainSocket.accept();
if(connectionSocket != null){
Client client = new Client(connectionSocket);
client.start();
Socket clientSocket = null;
clientSocket = mainSocket.accept();
try{
new Thread(new Client(clientSocket)).start();
}catch(SocketException e){
e.printStackTrace();
}
}
}
public static void cmdJoin() throws IOException, JSONException{
......
{"name" : "Bandar Behari","width" : 4,"height" : 4,"map" :[["R13", "R13", "R13", "R13"],["R13", "R13", "R14", "R14"],["R13", "R14", "R14", "R14"],["R13", "R14", "R14", "R14"]]}
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