twitter/finagle — Issue #63: How to use Finagle for Proxy? I encountered a problem. Options 
Author: zhupan
Created: 2012-02-21 11:01:27+00:00
State: open

There are my test codes. A simple proxy example:

EchoServer:
object EchoServer {
def main(args: Array[String]) {
val service = new Service[String, String] {
def apply(request: String) = {
println("I'm server,I received request message:" + request)
Future.value("I'm server. Where are you from?")
}
}
val server: Server = ServerBuilder()
.codec(StringCodec)
.bindTo(new InetSocketAddress(8082))
.name("Server")
.build(service)
}
}

EchoRouter:
object EchoRouter {
def main(args: Array[String]) {
val client: Service[String, String] = ClientBuilder()
.codec(StringCodec)
.hosts(new InetSocketAddress(8082))
.hostConnectionLimit(1)
.build()
val proxyService = new Service[String, String] {
def apply(request: String) = {
println("I'm router, I received request message:" + request)
client(request).onSuccess {
result => println("Router received result asynchronously: " + result)
} onFailure {
error => error.printStackTrace()
}
}
}
val server: Server = ServerBuilder()
.codec(StringCodec)
.bindTo(new InetSocketAddress(8081))
.name("Router")
.build(proxyService)
}
}

EchoClient:
object EchoClient {
def main(args: Array[String]) {
val client: Service[String, String] = ClientBuilder()
.codec(StringCodec)
.hosts(new InetSocketAddress(8081))
.hostConnectionLimit(1)
.build()
client("Hi,I'm client.\n").onSuccess {
result => println("Client received result asynchronously: " + result)
} onFailure {
error => error.printStackTrace()
} ensure {
client.release()
}
}
}

The problem is the EchoRouter can receive the message, But the EchoServer can't receive the message .

Is there any mistake i made? Can someone help me?

Here are version information.
scala version : 2.9.1
finagle-core_2.9.1 version:1.11.1