2015-02-07 77 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)) 

和它的作品