From 65daa3aee2de7c813e852b1627be5fd288eac0eb Mon Sep 17 00:00:00 2001 From: Grzegorz Piwowarek Date: Sun, 23 Oct 2016 11:57:11 +0200 Subject: [PATCH] Refactor examples --- core-java/src/main/java/com/baeldung/socket/EchoClient.java | 3 +-- .../src/main/java/com/baeldung/socket/EchoMultiServer.java | 2 +- core-java/src/main/java/com/baeldung/socket/EchoServer.java | 2 +- .../src/main/java/com/baeldung/socket/GreetClient.java | 3 +-- .../src/test/java/com/baeldung/socket/EchoMultiTest.java | 6 +++--- core-java/src/test/java/com/baeldung/socket/EchoTest.java | 2 +- 6 files changed, 8 insertions(+), 10 deletions(-) diff --git a/core-java/src/main/java/com/baeldung/socket/EchoClient.java b/core-java/src/main/java/com/baeldung/socket/EchoClient.java index e8ec97c80a..1ddf752a03 100644 --- a/core-java/src/main/java/com/baeldung/socket/EchoClient.java +++ b/core-java/src/main/java/com/baeldung/socket/EchoClient.java @@ -23,8 +23,7 @@ public class EchoClient { public String sendMessage(String msg) { try { out.println(msg); - String resp = in.readLine(); - return resp; + return in.readLine(); } catch (Exception e) { return null; } diff --git a/core-java/src/main/java/com/baeldung/socket/EchoMultiServer.java b/core-java/src/main/java/com/baeldung/socket/EchoMultiServer.java index 1177b82c87..2ece1ceebe 100644 --- a/core-java/src/main/java/com/baeldung/socket/EchoMultiServer.java +++ b/core-java/src/main/java/com/baeldung/socket/EchoMultiServer.java @@ -46,7 +46,7 @@ public class EchoMultiServer { clientSocket.getInputStream())); String inputLine; while ((inputLine = in.readLine()) != null) { - if ("".equals(inputLine)) { + if (".".equals(inputLine)) { out.println("bye"); break; } diff --git a/core-java/src/main/java/com/baeldung/socket/EchoServer.java b/core-java/src/main/java/com/baeldung/socket/EchoServer.java index 395624933c..3607afa7f5 100644 --- a/core-java/src/main/java/com/baeldung/socket/EchoServer.java +++ b/core-java/src/main/java/com/baeldung/socket/EchoServer.java @@ -18,7 +18,7 @@ public class EchoServer { clientSocket.getInputStream())); String inputLine; while ((inputLine = in.readLine()) != null) { - if ("".equals(inputLine)) { + if (".".equals(inputLine)) { out.println("good bye"); break; } diff --git a/core-java/src/main/java/com/baeldung/socket/GreetClient.java b/core-java/src/main/java/com/baeldung/socket/GreetClient.java index 7252827c87..21959c7469 100644 --- a/core-java/src/main/java/com/baeldung/socket/GreetClient.java +++ b/core-java/src/main/java/com/baeldung/socket/GreetClient.java @@ -26,8 +26,7 @@ public class GreetClient { public String sendMessage(String msg) { try { out.println(msg); - String resp = in.readLine(); - return resp; + return in.readLine(); } catch (Exception e) { return null; } diff --git a/core-java/src/test/java/com/baeldung/socket/EchoMultiTest.java b/core-java/src/test/java/com/baeldung/socket/EchoMultiTest.java index ccb5f48ddb..fcf353281d 100644 --- a/core-java/src/test/java/com/baeldung/socket/EchoMultiTest.java +++ b/core-java/src/test/java/com/baeldung/socket/EchoMultiTest.java @@ -23,7 +23,7 @@ public class EchoMultiTest { client.startConnection("127.0.0.1", PORT); String msg1 = client.sendMessage("hello"); String msg2 = client.sendMessage("world"); - String terminate = client.sendMessage(""); + String terminate = client.sendMessage("."); assertEquals(msg1, "hello"); assertEquals(msg2, "world"); @@ -37,7 +37,7 @@ public class EchoMultiTest { client.startConnection("127.0.0.1", PORT); String msg1 = client.sendMessage("hello"); String msg2 = client.sendMessage("world"); - String terminate = client.sendMessage(""); + String terminate = client.sendMessage("."); assertEquals(msg1, "hello"); assertEquals(msg2, "world"); assertEquals(terminate, "bye"); @@ -50,7 +50,7 @@ public class EchoMultiTest { client.startConnection("127.0.0.1", PORT); String msg1 = client.sendMessage("hello"); String msg2 = client.sendMessage("world"); - String terminate = client.sendMessage(""); + String terminate = client.sendMessage("."); assertEquals(msg1, "hello"); assertEquals(msg2, "world"); assertEquals(terminate, "bye"); diff --git a/core-java/src/test/java/com/baeldung/socket/EchoTest.java b/core-java/src/test/java/com/baeldung/socket/EchoTest.java index 76391f0f20..cb09d42f79 100644 --- a/core-java/src/test/java/com/baeldung/socket/EchoTest.java +++ b/core-java/src/test/java/com/baeldung/socket/EchoTest.java @@ -31,7 +31,7 @@ public class EchoTest { String resp1 = client.sendMessage("hello"); String resp2 = client.sendMessage("world"); String resp3 = client.sendMessage("!"); - String resp4 = client.sendMessage(""); + String resp4 = client.sendMessage("."); assertEquals("hello", resp1); assertEquals("world", resp2); assertEquals("!", resp3);