Commit ec6e903d authored by Trisha Gee's avatar Trisha Gee
Browse files

[Ch15] DailyAdviceServer has a try-with-resources for the server channel.

parent 33ea524d
Loading
Loading
Loading
Loading
+1 −3
Changes for src/main/java/ch15/DailyAdviceServer.java: 1 added line, 3 removed lines.
Original line number Diff line number Diff line
@@ -23,13 +23,11 @@ public class DailyAdviceServer {
  }

  public void go() {
    try {
      ServerSocketChannel serverChannel = ServerSocketChannel.open();
    try (ServerSocketChannel serverChannel = ServerSocketChannel.open()) {
      serverChannel.bind(new InetSocketAddress("localhost", 4242));

      while (serverChannel.isOpen()) {
        SocketChannel clientChannel = serverChannel.accept();

        PrintWriter writer = new PrintWriter(Channels.newOutputStream(clientChannel));
        String advice = getAdvice();
        writer.println(advice);