1

I write an echo app that send and receive '\0' terminated string

https://gist.github.com/jilen/10a664cd588af10b7d09

object Foo {

  implicit val S = scalaz.concurrent.Strategy.DefaultStrategy
  implicit val AG = tcp.DefaultAsynchronousChannelGroup
  ...

  def runServer() {
    def writeStr(str: String) = tcp.write(ByteVector(str.getBytes))
    val echoServer = (readStr |> serverLog("[Server] Receiving")).flatMap(writeStr)
    val server = tcp.server(addr, concurrentRequests = 1)(echoServer.repeat)
    server.flatMap(_.drain).run.run
  }

  def runClient() {
    val topic = async.topic[String]()
    val echoClient = (topic.subscribe |> clientLog("[Client] Inputing")).map { str =>
      tcp.write(ByteVector(str.getBytes) ++ Delimiter) ++ (readStr |> clientLog("[Client] Receiving"))
    }
    val client = tcp.connect(addr)(tcp.lift(echoClient))
    client.run.runAsync(println)
    io.stdInLines.to(topic.publish).run.run
  }
}

I run Foo.runServer() and Foo.runClient() on different terminal

And enter numbers 1 2 3 ... from the client console, but client receive no reply.

enter image description here enter image description here

What's wrong with my echo app ?

jilen
  • 5,633
  • 3
  • 35
  • 84

1 Answers1

0

Finally I rewrite the client as

val echoClient = tcp.subscribe.map(str => ByteVector(str.getBytes) ++ Delimiter)

val client = tcp.connect(addr)(tcp.writes(echoClient))

And it works

jilen
  • 5,633
  • 3
  • 35
  • 84