Commit e8f86b1f authored by adwisatya's avatar adwisatya
Browse files

debugging socket exception

parent 044d1698
......@@ -69,7 +69,7 @@ public class Client extends Thread{
toClient = new DataOutputStream(connectionSocket.getOutputStream());
fromClient.read(buffer);
clientSentence = new String(buffer);
checkCommand(clientSentence);
checkCommand(clientSentence);
}catch(IOException e){
try {
connectionSocket.close();
......@@ -96,11 +96,9 @@ public class Client extends Thread{
}
public void sendToClient(String tmpStr) throws IOException{
// new DataOutputStream(connectionSocket.getOutputStream()).writeBytes(tmpStr);
// new DataOutputStream(connectionSocket.getOutputStream());
// OutputStream output = connectionSocket.getOutputStream();
PrintStream out = new PrintStream(connectionSocket.getOutputStream());
out.print(tmpStr);
}
public void checkCommand(String cmd) throws IOException, NoSuchAlgorithmException, JSONException {
cmdJoin();
......@@ -637,13 +635,5 @@ public class Client extends Thread{
}else{
System.out.println("tidak ada");
}
// 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);
// }
}
}
......@@ -26,27 +26,26 @@ import static thealchemist.Client.myPort;
public class TCPServer {
static int portNumber = 6789;
public static void main(String argv[]) throws Exception{
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 ;
// Socket clientSocket = null;
// mainSocket = new ServerSocket(portNumber);
// System.out.println("Start listening...");
//
// while(true){
// clientSocket = mainSocket.accept();
// new Thread(new Client(clientSocket)).start();
// cmdJoin();
// while(!mainSocket.isClosed()){
// Socket connectionSocket = mainSocket.accept();
// if(connectionSocket != null){
// Client client = new Client(connectionSocket);
// client.start();
// }
// }
ServerSocket mainSocket ;
Socket clientSocket = null;
mainSocket = new ServerSocket(portNumber);
System.out.println("Start listening...");
while(true){
clientSocket = mainSocket.accept();
new Thread(new Client(clientSocket)).start();
}
}
public static void cmdJoin() throws IOException, JSONException{
......
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