我编写了一个 echo 应用程序send
并receive
'\0'
终止了字符串
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
}
}
我在不同的终端上Foo.runServer()
运行Foo.runClient()
并从客户端控制台输入数字1 2 3 ...,但客户端没有收到回复。
我的回声应用程序有什么问题?