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.
What's wrong with my echo app ?