Commit 1ab55b7a authored by Rafi Ramadhan's avatar Rafi Ramadhan
Browse files

clientHandler

parents ecf70eb1 74590d5f
......@@ -9,6 +9,7 @@ package grandquestserver;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.sql.SQLException;
......@@ -24,7 +25,7 @@ public class ClientHandler extends Thread {
private Socket socketListener;
public ClientHandler(ServerSocket sock) throws IOException {
System.out.println("Waiting for client on port " + sock.getLocalPort() + "...");
System.out.println("Waiting for client on " + InetAddress.getLocalHost().getHostAddress()+ ":" + sock.getLocalPort() + "...");
socketListener = sock.accept();
System.out.println("Just connected to " + socketListener.getRemoteSocketAddress());
}
......@@ -39,11 +40,12 @@ public class ClientHandler extends Thread {
response = in.readUTF();
DataOutputStream out = new DataOutputStream(socketListener.getOutputStream());
switch (parse.parseJSON(response, "method")) {
case "login":
String login = handler.Login(response);
out.writeUTF(login);
out.writeUTF(handler.Login(response));
break;
case "signup":
out.writeUTF(handler.Signup(response));
......
......@@ -9,6 +9,8 @@ package grandquestserver;
import java.io.IOException;
import java.net.ServerSocket;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
/**
*
......@@ -26,9 +28,13 @@ public class GrandQuestServer {
*/
public static void main(String[] args) throws IOException, SQLException, ClassNotFoundException, InstantiationException, IllegalAccessException {
int port = 8000;
List<Thread> clientList = new ArrayList<>();
ServerSocket serverSock = new ServerSocket(port);
Thread t = new ClientHandler(serverSock);
t.start();
while(true) {
Thread t = new ClientHandler(serverSock);
t.start();
clientList.add(t);
}
//DBHandler database = new DBHandler();
//database.addInventory("ardi", 2);
}
......
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