Skip to content

Commit 78bafb6

Browse files
committed
KnockKnockServer Issues Windows
1 parent e9a3bb4 commit 78bafb6

File tree

3 files changed

+34
-16
lines changed

3 files changed

+34
-16
lines changed

KnockSockets/KnockKnockClient.java

+6-9
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,18 @@ public static void main(String[] args) throws IOException {
2323
)
2424
{
2525
BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
26-
String fromServer;
2726
String fromUser;
27+
String fromServer = "";
2828

29-
byte[] messageByte = new byte[1000];
30-
boolean end = false;
31-
String dataString = "";
29+
byte[] messageByte = new byte[10000];
3230

3331
while (in.available()>0) {
34-
//No muy util ya que no se limpia el buffer
3532
int bytesRead = in.read(messageByte);
36-
dataString += new String(messageByte, 0, bytesRead);
33+
fromServer += new String(messageByte, 0, bytesRead);
34+
35+
System.out.println(fromServer);
36+
fromServer = "";
3737

38-
System.out.println(dataString);
39-
// System.out.println(fromServer);
40-
dataString = "";
4138
fromUser = stdIn.readLine();
4239
if (fromUser != null) {
4340
// enviamos al server peticion del usuario

KnockSockets/KnockKnockProtocol.java

+26-5
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,36 @@ public class KnockKnockProtocol {
1616
public String processInput(String theInput) {
1717
String theOutput = "";
1818

19+
//only first time --> protocol
1920
if (theInput == null){
2021
theOutput = "------------------------------\n"
2122
+ "------------------------------\n"
2223
+ "------------------------------\n"
23-
+ "---------W e l c o m e--------\n"
24+
+ "---------"+ANSI_GREEN+"W e l c o m e"+ANSI_RESET+"--------\n"
2425
+ "------------------------------\n"
2526
+ "------------------------------\n"
2627
+ "------------------------------\n";
2728
theOutput += this.getCommandsAvailable();
2829
}else{
2930
switch (theInput) {
31+
case "0":
32+
theOutput = "Hello ma' friend!";
33+
break;
34+
case "1":
35+
theOutput = "John Tell me that today is raining";
36+
break;
37+
case "2":
38+
theOutput = "HAHHAA!";
39+
break;
40+
case "3":
41+
theOutput = "¡Good Jaming!";
42+
break;
43+
case "4":
44+
theOutput = this.getCommandsAvailable();
45+
break;
46+
case "5":
47+
theOutput = "Bye ma' friend!";
48+
break;
3049
default:
3150
theOutput += this.getCommandsAvailable();
3251
break;
@@ -39,10 +58,12 @@ public String processInput(String theInput) {
3958
private String getCommandsAvailable(){
4059
String outString = "";
4160
outString = ANSI_YELLOW + "Comandos disponibles:" + ANSI_RESET + "\n";
42-
outString += "[0] \n"
43-
+ "[1] \n"
44-
+ "[2] \n"
45-
+ "[3] \n";
61+
outString += ANSI_PURPLE+"[0]"+ANSI_RESET+" Say Hello Server\n"
62+
+ ANSI_PURPLE+"[1]"+ANSI_RESET+" Call to John Doe\n"
63+
+ ANSI_PURPLE+"[2]"+ANSI_RESET+" Make a laugh man\n"
64+
+ ANSI_PURPLE+"[3]"+ANSI_RESET+" Play some good..\n"
65+
+ ANSI_PURPLE+"[4]"+ANSI_RESET+" Show commands..\n"
66+
+ ANSI_PURPLE+"[5]"+ANSI_RESET+" Exit...\n";
4667
return outString;
4768
}
4869
}

KnockSockets/KnockKnockServer.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ public class KnockKnockServer {
66
public static void main(String[] args) throws IOException {
77

88
if (args.length != 1) {
9-
System.err.println("Usage: java EchoServer <port_number>");
9+
System.err.println("Usage: java KnockKnockServer <port_number>");
1010
System.exit(1);
1111
}
1212

@@ -35,7 +35,7 @@ public static void main(String[] args) throws IOException {
3535
outputLine = kkp.processInput(inputLine);
3636
System.out.println(outputLine);
3737
out.println(outputLine);
38-
if (outputLine.equals("Bye."))
38+
if (outputLine.equals("Bye ma' friend!"))
3939
break;
4040
}
4141
} catch (IOException e) {

0 commit comments

Comments
 (0)