Commit 69a6797e authored by Rafi Ramadhan's avatar Rafi Ramadhan
Browse files

modify

parent 6d4eafbe
/src/server/TrialServer/nbproject/private/
/src/server/GrandQuestServer/nbproject/private/
/src/server/GrandQuestServer/build/
\ No newline at end of file
/src/server/GrandQuestServer/build/
/src/server/GrandQuestServer/dist/
\ No newline at end of file
......@@ -27,9 +27,11 @@ dist.dir=dist
dist.jar=${dist.dir}/GrandQuestServer.jar
dist.javadoc.dir=${dist.dir}/javadoc
excludes=
file.reference.json-simple-1.1.1.jar=lib\\json-simple-1.1.1.jar
includes=**
jar.compress=false
javac.classpath=
javac.classpath=\
${file.reference.json-simple-1.1.1.jar}
# Space-separated list of extra javac options
javac.compilerargs=
javac.deprecation=false
......
......@@ -19,7 +19,7 @@ public class GrandQuestServer {
* @throws java.io.IOException
*/
public static void main(String[] args) throws IOException {
int port = 80;
int port = 8000;
Thread t = new Server(port);
t.start();
}
......
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package grandquestserver;
/**
*
* @author Rakhmatullah Yoga S
*/
import org.json.simple.*;
import org.json.simple.parser.JSONParser;
import java.util.*;
import org.json.simple.parser.ParseException;
public class JSONParse {
public Map createJSON(List<String> param, List<String> value) {
Map request = new LinkedHashMap();
for(int i=0; i<param.size(); i++) {
request.put(param.get(i), value.get(i));
}
return request;
}
public String parseJSON(String input, String key) throws ParseException {
JSONParser parser = new JSONParser();
Object respond = parser.parse(input);
JSONObject obj = (JSONObject) respond;
String response = (String) obj.get(key);
return response;
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package grandquestserver;
/**
*
* @author Rakhmatullah Yoga S
*/
public class JSONParser {
}
......@@ -12,6 +12,11 @@ import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketTimeoutException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.json.simple.*;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
/**
*
......@@ -26,6 +31,8 @@ public class Server extends Thread {
@Override
public void run()
{
String response;
JSONParse parse = new JSONParse();
while(true)
{
try
......@@ -37,11 +44,19 @@ public class Server extends Thread {
+ server.getRemoteSocketAddress());
DataInputStream in =
new DataInputStream(server.getInputStream());
System.out.println(in.readUTF());
response = in.readUTF();
System.out.println(response);
System.out.println(parse.parseJSON(response, "method"));
System.out.println(parse.parseJSON(response, "username"));
System.out.println(parse.parseJSON(response, "password"));
DataOutputStream out =
new DataOutputStream(server.getOutputStream());
out.writeUTF("Thank you for connecting to "
+ server.getLocalSocketAddress() + "\nGoodbye!");
} catch (ParseException ex) {
Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, ex);
}
}catch(SocketTimeoutException s)
{
......
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