简体   繁体   English

发送一个TCP / IP消息AKKA演员

[英]Send a TCP / IP message AKKA actor

Is it possible to send a message over TCP / IP to an AKKA actor? 是否可以通过TCP / IP向AKKA演员发送消息?

For example, write a client like: 例如,写一个客户端,如:

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

That could send messages to AKKA actor? 这可以发送消息给AKKA演员?

Thanks 谢谢

Elaborating a little more on Viktor's response, the minimal example would be 再详细说明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)
    }
  })
}

Then in a different shell start telnet localhost 1234 and start typing, you'll see one actor log message per line. 然后在另一个shell中启动telnet localhost 1234并开始输入,你会看到每行有一个actor日志消息。

Yes, and no. 是的,不。 You'll have to use Akka IO module or Akka Camel module (with netty or mina component): 您将不得不使用Akka IO模块或Akka Camel模块(使用netty或mina组件):

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

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

If you are trying to send a message across a remote actor using IP, Why don't you try the Akka Remote Actor system? 如果您尝试使用IP在远程actor上发送消息,为什么不尝试使用Akka Remote Actor系统? "Read it here" “在这里阅读”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM