开发者

Akka Actor can't connect to remote server where Scala Actor could

开发者 https://www.devze.com 2023-02-17 17:16 出处:网络
I got a little problem. I just moved the client-server-communication of my current project from remote Scala Actors to remote开发者_运维问答 Akka Actors.

I got a little problem. I just moved the client-server-communication of my current project from remote Scala Actors to remote开发者_运维问答 Akka Actors.

Everything worked fine while testing on my local machine but once I tried to run the code with the client and server at different machines the client can't reach the server anymore (I get a java.nio.channels.NotYetConnectedException). I double and tripple checked the ip and port being used. It's the same host data I used in the code with the Scala actors (which by the way still work. So apparently nothing changed at the firewall settings and server is technically reachable)

Here are the important parts of the code (which I mostly copy pasted from akkas homepage):

On the server actor

import akka.actor.Actor._
import akka.actor.{Actor, ActorRef, Supervisor}

override def preStart = {

  // I also tried the servers external ip here 
  remote.start(host, 1357) 

  // SERVER_SERVICE_NAME is a string constant in a trait that both server
  // and client extend
  // all actual work is refered to SessionActor
  remote.registerPerSession(SERVER_SERVICE_NAME, actorOf[SessionActor])
}

and on the client:

import akka.actor.Actor._
import akka.actor.{Actor, ActorRef, Supervisor}

override def preStart = {

  // CLIENT_SERVICE_NAME is a string constant
  Actor.remote.start("localhost", 5678).register(CLIENT_SERVICE_NAME, self)

  // I also tried "Thread sleep 1000" here just in case

  // internalServer is a private var of the type Option[ActorRef]
  // host and serverPort are actually read from a propertiesfile. Guess this
  // doesn't matter. I checked them.
  internalServer = Some(
    remote.actorFor(SERVER_SERVICE_NAME, host, serverPort)
  )

  // Again I tried "Thread sleep 1000" here. Didn't help neither

  internalServer foreach (server => {
    (server !! Ping) foreach (_ match { // !!! this is where the exception is thrown !!!
        case Pong   => println("connected")
        case _      => println("something's fishy")
      })
    })

}

I am using: Scala 2.8.1 (although I'm no sure whether the machines at my client are 2.8 or 2.8.1, I use the scala-library.jar from the akka distribution) Akka 1.0

I know that you can't debugg my code her but I'd be very thankfull for any kind of hint or idea what might be going wrong here.

P.S.: the Exception is thrown within a splitsecond after trying to send the Ping. So I didn't bother increasing the Timeout-time.


DISCLAIMER: I am the PO of Akka

Try using a raw IP address instead of a hostname in remote.start(), if that doesn't solve it you have 2 options:

  1. Make sure that the two parties can DNS resolve eachother
  2. Upgrade to current master (1.1-SNAPSHOT), since I've made quite a few changes to avoid name resolution.

Does that help?

0

精彩评论

暂无评论...
验证码 换一张
取 消