Skip to content
Snippets Groups Projects
Commit c5f9fa6d authored by mateis00's avatar mateis00
Browse files

Dispair -> History Works fine but freezes input:(

parent 76e58e86
No related branches found
No related tags found
No related merge requests found
...@@ -5,8 +5,11 @@ import java.net.*; ...@@ -5,8 +5,11 @@ import java.net.*;
import java.nio.*; import java.nio.*;
import java.security.*; import java.security.*;
import java.util.*; import java.util.*;
import java.text.*;
import javax.lang.model.util.ElementScanner14;
import java.text.*;
//Wrong Command gives Out of bounce -> Please fix Use switch!
public class Client { public class Client {
private String ip = ""; private String ip = "";
private int port = -1; private int port = -1;
...@@ -97,10 +100,57 @@ public class Client { ...@@ -97,10 +100,57 @@ public class Client {
date(); date();
eingabe =""; eingabe ="";
} }
else if(eingabe.equalsIgnoreCase("history")){
history(eingabe);
eingabe ="";
}
} }
// "close" -> While schleife endet, constructor endet, client ist beendet // "close" -> While schleife endet, constructor endet, client ist beendet
} }
private void history(String command) throws IOException{
try {
zumServer.write(command+"\n");
zumServer.flush();
String input;
int i =0;
String[] behinderung = command.split(" ");
if(behinderung.length == 2)
{
try{
i = Integer.parseInt(behinderung[1]);
}catch( NumberFormatException re)
{
System.err.println("Err Format kaput cannot parse");
}
}
else{
i = 1;
}
while((input = vomServer.readLine()) != "HstrLstDone")
{
/* if(input == "HstrLstDone")
{
System.out.println("History Completed");
return;
}else
{*/
System.out.println(i+ ": "+ input);
i++;
//}
}
return;
}
catch(IOException e) {
System.err.println("Probleme bei void Ping() (IOException)");
return;
}
}
// Aufruf "ping": // Aufruf "ping":
private void ping() throws IOException{ private void ping() throws IOException{
try { try {
......
...@@ -64,6 +64,7 @@ public class Server{ ...@@ -64,6 +64,7 @@ public class Server{
command =""; command ="";
break; break;
case "echo": case "echo":
historyList.add(command); historyList.add(command);
Echo(command); Echo(command);
...@@ -71,6 +72,7 @@ public class Server{ ...@@ -71,6 +72,7 @@ public class Server{
break; break;
case "current": case "current":
switch(words[1].toLowerCase()) switch(words[1].toLowerCase())
{ {
case "time": case "time":
...@@ -92,19 +94,41 @@ public class Server{ ...@@ -92,19 +94,41 @@ public class Server{
command =""; command ="";
break; break;
} }
case "history": case "history":
System.out.println("Request for History");
if (words.length == 2) {
try
{
int x = Integer.parseInt(words[1]);
if(x<0)
{
System.err.println("Err: Parsed Integer is negative");
command = "";
break;
}
History(x);
command = "";
break;
} catch (NumberFormatException e)
{
System.err.println("Err: Client Provided HistoryRequest with not parsable Integer");
command = "";
break;
}
} else {
historyList.add(command); historyList.add(command);
History(); History();
command = ""; command = "";
break; break;
}
case "close": case "close":
historyList.clear();
break; break;
default: default:
historyList.add("CmdErr: "+command);
writer.write("Err Wrong or No command\n"); writer.write("Err Wrong or No command\n");
System.out.println("Err Wrong or No command"); System.out.println("Err Wrong or No command");
writer.flush(); writer.flush();
...@@ -121,16 +145,35 @@ public class Server{ ...@@ -121,16 +145,35 @@ public class Server{
private void History() private void History()
{ {
try{ try{
for(int i = 0;i < historyList.size();i++) for (String s : historyList) {
{
writer.write(i + ": " + historyList.get(i));
writer.write(s);
writer.newLine();
} }
writer.write("HstrLstDone"); writer.write("HstrLstDone\n");
writer.flush(); writer.flush();
return;
}catch (IOException err) }catch (IOException err)
{ {
System.err.println("History Error"); System.err.println("History Error");
return;
}
}
private void History(int parsed)
{
try{
writer.write(parsed+1 + " " + historyList.get(parsed)+" \n");
writer.newLine();
writer.write("HstrLstDone\n");
writer.flush();
return;
}catch (IOException err)
{
System.err.println("History Error");
return;
} }
} }
...@@ -178,6 +221,7 @@ public class Server{ ...@@ -178,6 +221,7 @@ public class Server{
}catch (IOException err) }catch (IOException err)
{ {
System.err.println("ServerErr Echo"); System.err.println("ServerErr Echo");
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment