A TCP client streaming messages, then shutting the server down

The complete source of networkTypes_tcp_client_stream.ek9, compiled by the EK9 compiler. Shown on networkTypes.html.

#!ek9
defines module site.networkTypes.tcpClientStream

  defines function
    shutdownFunction()
      -> tcpClient as TCP
      <- response as String: `Connection failed ${tcpClient}`

      if tcpClient?
        try
          -> connection <- tcpClient.connect()
          if connection?
            connection.output().println("SHUTDOWN")
            response: `Received response [${connection.input().next()} from ${tcpClient}]`
          else
            response: `Failed to connect on [${tcpClient}]`
      else
        response: `Failed to get TCP client running [${tcpClient}]`

    processingFunction() as abstract
      -> input as String
      <- response as String?

  defines program
    TCPClient2()
      ->
        processingPort as Integer
        controlPort as Integer

      stdout <- Stdout()
      localhost <- Networking().loopbackV4()
      try
        -> processingClient <- TCP(NetworkProperties(localhost, processingPort))

        if processingClient?
          try
            -> connection <- processingClient.connect()
            sender <- (connection) is processingFunction as function
              connection.output().println(input)
              response: connection.input().next()

            cat ["one", "two", "Alpha", "Beta", "Zeta", "end", "begin"] | map with sender > stdout

      //The control client is closeable, so it is acquired in a try and lent to the function.
      try
        -> controlClient <- TCP(NetworkProperties(localhost, controlPort))
        stdout.println(shutdownFunction(controlClient))

Download networkTypes_tcp_client_stream.ek9