2015-02-07 80 views
1

我写sendreceive'\0'终止字符串scalaz流TCP`echo`应用不起作用

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 ...,但客户端收不到回复。

enter image description here enter image description here

这有什么错我的回音的应用程序?

+0

什么是服务器的类型?它的一个'进程[任务,进程[任务,Throwable \/A]]]'对吗?所以'server.run.run'是一个'Process [Task,Throwable \/A]'你扔掉了吧? – stew 2015-03-10 04:12:54

+0

@stew如何运行服务器? – jilen 2015-03-10 04:13:50

+0

我对这些类型是否正确?如果是这样的话,似乎你应该运行这个过程而不是把它扔掉。 – stew 2015-03-10 15:29:11

回答

0

最后我重写客户端作为

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

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

和它的作品