Hi Chris,

Glad that you found the problem. Happy Hakking!

B/

On 3 April 2014 at 18:47:28, Chris Vaas ([email protected]) wrote:

Dear Björn,
you were perfectly right. It seems that the problem was selfmade. Thank you 
very much for your time. Problem solved :-)

On Thursday, April 3, 2014 9:59:39 AM UTC+2, Chris Vaas wrote:
The following code is a basic TCP server and client, that should communicate. 
But the log is as shown below the source code. No data is ever received by the 
connection handler, after several connections got handled correctly. What am I 
missing here?


package examples

import akka.io.Tcp
import akka.actor.Actor
import akka.io.Tcp.Bound
import akka.io.Tcp.CommandFailed
import akka.io.IO
import akka.io.Tcp.Connected
import org.slf4j.LoggerFactory
import akka.actor.Props
import utils.ConfigurationUtils
import java.net.InetSocketAddress
import akka.actor.Stash
import akka.actor.ActorSystem
import akka.util.ByteString

object TCP_Debug extends App {
  val name = this.getClass().getName()
  val logger = LoggerFactory.getLogger(name)

  logger.info("Starting server and flooder")
  val system = ActorSystem("Midas")
  val sever = system.actorOf(Props[Server], "Server")
  val flooder = system.actorOf(Props[AlarmFlooder], "Flooder")

  for (i <- 1 to 10) {
    Thread.sleep(1000)
    flooder ! Msg("Message " + i)
  }
}

class Server extends Actor {
  import Tcp._
  import context._

  val name = this.getClass.getName
  val logger = LoggerFactory.getLogger(name)

  IO(Tcp) ! Bind(self, new InetSocketAddress("0.0.0.0", 4444))

  def receive = {
    case Bound(localAddress) =>
      logger.info("Bound to {}:{}", localAddress.getAddress, 
localAddress.getPort)
    case CommandFailed(Bind(_, localAddress: InetSocketAddress, _, _, _)) =>
      logger.info("Could not bind to {}:{}", localAddress.getHostName, 
localAddress.getPort)
      context stop self
    case c @ Connected(remote, local) =>
      val connection = sender()
      val handler = context.actorOf(Props[ConnectionHandler])
      connection ! Register(handler)
      logger.info("Client connected from {}:{}", remote.getHostName, 
remote.getPort)
    case a @ _ => logger.info("Unknown message: " + a.toString)
  }
}

private class ConnectionHandler extends Actor {
  import Tcp._
  import scala.xml._

  val name = this.getClass.getName
  val logger = LoggerFactory.getLogger(name)

  def receive = {
    case Received(data) => {
      logger.info("Received {} bytes of data", data.length)
    }
    case PeerClosed =>
      logger.info("Connection closed")
      context stop self
    case a @ _ => logger.info("Unknown message: " + a.toString)
  }
}

case class Msg(content: String)

class AlarmFlooder <s
...
--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ: 
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups "Akka 
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.
-- 
Björn Antonsson
Typesafe – Reactive Apps on the JVM
twitter: @bantonsson

JOIN US. REGISTER TODAY!
Scala
Days
June 16th-18th,
Berlin

-- 
>>>>>>>>>>      Read the docs: http://akka.io/docs/
>>>>>>>>>>      Check the FAQ: 
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>>      Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups "Akka 
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to