【问题标题】:Send a TCP / IP message AKKA actor发送 TCP/IP 消息 AKKA 演员
【发布时间】:2012-10-09 05:02:04
【问题描述】:

是否可以通过 TCP/IP 向 AKKA 演员发送消息?

例如,写一个这样的客户端:

mySocket = new Socket("theactor", 75);
os = new DataOutputStream(smtpSocket.getOutputStream());
os.writeBytes("HELLO");    

这可以向 AKKA 演员发送消息吗?

谢谢

【问题讨论】:

    标签: java scala tcp akka actor


    【解决方案1】:

    是的,也不是。您必须使用 Akka IO 模块或 Akka Camel 模块(带有 netty 或 mina 组件):

    http://doc.akka.io/docs/akka/snapshot/scala/io.html

    http://doc.akka.io/docs/akka/snapshot/java/camel.html

    【讨论】:

      【解决方案2】:

      详细说明 Viktor 的回应,最简单的例子是

      import akka.actor._
      import ActorDSL._
      import java.net.InetSocketAddress
      
      object Server extends App {
        implicit val sys = ActorSystem("telnet")
      
        actor(new Act with ActorLogging {
          IOManager(context.system) listen new InetSocketAddress(1234)
          become {
            case IO.NewClient(server) ⇒
              server.accept()
            case IO.Read(handle, bytes) ⇒
              log.info("got {} from {}", bytes.decodeString("utf-8"), handle)
          }
        })
      }
      

      然后在另一个 shell 中启动 telnet localhost 1234 并开始输入,您将看到每行一个参与者日志消息。

      【讨论】:

        【解决方案3】:

        如果您尝试使用 IP 通过远程 Actor 发送消息,您为什么不尝试 Akka Remote Actor 系统? "Read it here"

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2015-03-28
          • 1970-01-01
          • 1970-01-01
          • 2014-12-03
          • 2018-09-29
          • 2014-12-02
          • 1970-01-01
          • 2014-07-10
          相关资源
          最近更新 更多