dumitru
dumitru

Reputation: 2108

akka io tcp server

I am using the new Akka IO and followed this tutorial(which is a simple server-client application). My server actor system code looks like this:

// create the sever system
    ActorSystem tcpServerSystem = ActorSystem.create("tcp-server-system");


    // create the tcp actor
    final ActorRef tcpServer = Tcp.get(tcpServerSystem).manager();

    // create the server actor;
    ActorRef serverActor = tcpServerSystem.actorOf(new Props(ServerActor.class).withRouter(new RoundRobinRouter(5)), "server");

    // tell the tcp server to use an actor for listen connection on;
    final List<Inet.SocketOption> options = new ArrayList<Inet.SocketOption>();
    options.add(TcpSO.reuseAddress(true));

    tcpServer.tell(TcpMessage.bind(serverActor, new InetSocketAddress("127.0.0.1", 12345), 10, options),
            serverActor);

The ServerActor class it's just a plain actor that on it's onReceive does the followings:

logger.info("Received: " + o);
    if (o instanceof Tcp.Connected){
        connectionActor = getSender();
        connectionActor.tell(TcpMessage.register(getSelf()), getSelf());
        ByteStringBuilder byteStringBuilder = new ByteStringBuilder();
        byteStringBuilder.putBytes("Hello Worlds".getBytes());
        connectionActor.tell(TcpMessage.write(byteStringBuilder.result()), getSelf());
    }

I am trying to test the server actor using netcat and have this "strange" behaviour: only the first client that connect tot the server is receiving the message send from the server. The nexts clients could connect to the server but does not receive the message. Also in debug mode the server actor doesn't get the Tcp.Connected message(except for the first connected client), so a registration message could not be sent to the client, althought the next clients could connect.

Upvotes: 0

Views: 2286

Answers (1)

Bj&#246;rn Antonsson
Bj&#246;rn Antonsson

Reputation: 1019

this is a known issue in the 2.2-M1 milestone, where the problem was that the TcpListener didn't register AcceptInterest on the selector unless it reached the configured BatchAcceptLimit, leading to it not being notified of new accepts if there where only a few connections pending.

It has been fixed and will be part of the next milestone release.

Upvotes: 1

Related Questions