我正在寻找一些简单和简短的例子,如何连接和进行交互(两种方式)与tcp套接字。换句话说,如何编写Scala2.10应用程序(使用akka-camel或netty库)来与tcp进程(套接字)通信。
我在互联网上发现了大量的文献,但是所有的东西都是旧的(寻找Scala2.10)和/或反对。
提前感谢!
发布于 2013-01-26 11:36:35
嗯,我在找这样的东西:
1.服务器:
import akka.actor._
import akka.camel.{ Consumer, CamelMessage }
class Ser extends Consumer {
def endpointUri = "mina2:tcp://localhost:9002"
def receive = {
case message: CamelMessage => {
//log
println("looging, question:" + message)
sender ! "server response to request: " + message.bodyAs[String] + ", is NO"
}
case _ => println("I got something else!??!!")
}
}
object server extends App {
val system = ActorSystem("some")
val spust = system.actorOf(Props[Ser])
}2. Client:
import akka.actor._
import akka.camel._
import akka.pattern.ask
import scala.concurrent.duration._
import akka.util.Timeout
import scala.concurrent.Await
class Producer1 extends Actor with Producer {
def endpointUri = "mina2:tcp://localhost:9002"
}
object Client extends App {
implicit val timeout = Timeout(10 seconds)
val system2 = ActorSystem("some-system")
val producer = system2.actorOf(Props[Producer1])
val future = producer.ask("Hello, can I go to cinema?")
val result = Await.result(future, timeout.duration)
println("Is future over?="+future.isCompleted+";;result="+result)
println("Ende!!!")
system2.shutdown
println("system2 ended:"+system2.isTerminated)我知道这是用http://doc.akka.io/docs/akka/2.1.0/scala/camel.html写的和描述得很好的一切。但是,如果您是新手,您需要全部阅读几遍才能构建非常简单的客户机-服务器应用程序。我认为某种“激励榜样”将是非常受欢迎的。
发布于 2013-01-24 08:06:55
我想你已经查过Akka文档了吗?http://doc.akka.io/docs/akka/2.1.0/scala/camel.html
在Akka 2.1.0中,他们改进了akka-骆驼模块,使其完全更新(以前有点过时)。
还有一个骆驼-阿克卡视频演示,涵盖了一个真实的用例:http://www.davsclaus.com/2012/04/great-akka-and-camel-presentation-video.html。
https://stackoverflow.com/questions/14484096
复制相似问题