Commit 3e2d779e authored by adwisatya's avatar adwisatya
Browse files

Revisi client

parent 87131815
......@@ -26,7 +26,7 @@ user.properties.file=C:\\Users\\Muldani\\AppData\\Roaming\\NetBeans\\8.0\\build.
<<<<<<< HEAD
user.properties.file=C:\\Users\\A450LC W8\\AppData\\Roaming\\NetBeans\\8.0.1\\build.properties
=======
user.properties.file=C:\\Users\\Muldani\\AppData\\Roaming\\NetBeans\\8.0\\build.properties
user.properties.file=C:\\Users\\adwisatya\\AppData\\Roaming\\NetBeans\\8.0.2\\build.properties
>>>>>>> 02323e945e52f7a247d213f954c360232adc5b0e
>>>>>>> 43edd7f388dc28ed09074436ded7167fffce2bcf
>>>>>>> 08b39e9ffc058e8856fd1186a9d3fbe46d951054
......
......@@ -8,10 +8,12 @@ package thealchemist.engine;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.net.Socket;
import java.security.MessageDigest;
......@@ -28,6 +30,10 @@ import org.json.JSONObject;
* @author adwisatya
*/
public class Connection {
Socket miniSocket;
private String clientSentence;
private BufferedReader fromClient;
private DataOutputStream toClient;
String response;
String request;
// private static String URL = "167.205.32.46";
......@@ -36,27 +42,33 @@ public class Connection {
private static String URL = "localhost";
private static int defPort = 6789;
private String token = "kosong";
// public Connection(Socket c) throws IOException{
// connectionSocket = c;
// }
public String sendRequest(String JSON) throws IOException, JSONException{
Socket miniSocket = new Socket(URL,defPort);
miniSocket = new Socket(URL,defPort);
char[] buffer = new char[1024];
JSONObject obj = new JSONObject(JSON);
PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(miniSocket.getOutputStream())));
out.println(obj);
out.println();
out.flush();
InputStream dataInputStream = new DataInputStream(miniSocket.getInputStream());
InputStreamReader inputStreamReader = new InputStreamReader(dataInputStream);
BufferedReader in = new BufferedReader(inputStreamReader);
in.read(buffer);
response = new String(buffer);
in.close();
sendToClient(obj.toString());
// PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(miniSocket.getOutputStream())));
// out.print(obj);
// //out.print();
// out.flush();
fromClient = new BufferedReader(new InputStreamReader(miniSocket.getInputStream()));
fromClient.read(buffer);
clientSentence = new String(buffer);
return response;
// InputStream dataInputStream = new DataInputStream(miniSocket.getInputStream());
// InputStreamReader inputStreamReader = new InputStreamReader(dataInputStream);
// BufferedReader in = new BufferedReader(inputStreamReader);
// in.read(buffer);
// response = new String(buffer);
// in.close();
return clientSentence;
}
public void setToken(String JSONString){
......@@ -261,5 +273,9 @@ public class Connection {
return img;
}
public void sendToClient(String tmpStr) throws IOException{
PrintStream out = new PrintStream(miniSocket.getOutputStream());
out.print(tmpStr);
System.out.println(tmpStr);
}
}
......@@ -25,7 +25,7 @@ user.properties.file=C:\\Users\\Muldani\\AppData\\Roaming\\NetBeans\\8.0\\build.
<<<<<<< HEAD
user.properties.file=C:\\Users\\A450LC W8\\AppData\\Roaming\\NetBeans\\8.0.1\\build.properties
=======
user.properties.file=C:\\Users\\Muldani\\AppData\\Roaming\\NetBeans\\8.0\\build.properties
user.properties.file=C:\\Users\\adwisatya\\AppData\\Roaming\\NetBeans\\8.0.2\\build.properties
>>>>>>> 02323e945e52f7a247d213f954c360232adc5b0e
>>>>>>> 43edd7f388dc28ed09074436ded7167fffce2bcf
>>>>>>> 08b39e9ffc058e8856fd1186a9d3fbe46d951054
......
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