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 tags found
No related merge requests found
......@@ -5,8 +5,11 @@ import java.net.*;
import java.nio.*;
import java.security.*;
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 {
private String ip = "";
private int port = -1;
......@@ -97,10 +100,57 @@ public class Client {
date();
eingabe ="";
}
else if(eingabe.equalsIgnoreCase("history")){
history(eingabe);
eingabe ="";
}
}
// "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":
private void ping() throws IOException{
try {
......
......@@ -64,6 +64,7 @@ public class Server{
command ="";
break;
case "echo":
historyList.add(command);
Echo(command);
......@@ -71,6 +72,7 @@ public class Server{
break;
case "current":
switch(words[1].toLowerCase())
{
case "time":
......@@ -92,19 +94,41 @@ public class Server{
command ="";
break;
}
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);
History();
command = "";
break;
}
case "close":
historyList.clear();
break;
default:
historyList.add("CmdErr: "+command);
writer.write("Err Wrong or No command\n");
System.out.println("Err Wrong or No command");
writer.flush();
......@@ -121,16 +145,35 @@ public class Server{
private void History()
{
try{
for(int i = 0;i < historyList.size();i++)
{
writer.write(i + ": " + historyList.get(i));
for (String s : historyList) {
writer.write(s);
writer.newLine();
}
writer.write("HstrLstDone");
writer.write("HstrLstDone\n");
writer.flush();
return;
}catch (IOException err)
{
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{
}catch (IOException err)
{
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