Hi Every one
i wrote this code for read Port 25
class Asker(connection: ActorRef) extends Actor {
import Tcp._
connection ! Register(self);
def receive = {
case x =>
val parent = sender()
connection ! x
context become {case x => parent ! x;context.unbecome()}
}
}
trait TcpAskSupport {
self: Actor =>
def asker(connection: ActorRef) =
context.child(connection.path.name + "Asker")
.getOrElse(context.actorOf(Props(classOf[Asker], connection),
connection.path.name + "Asker"))
}
class Client2 extends Actor with TcpAskSupport with ActorLogging{
import Tcp._
import context.system
val from="[email protected]"
val to ="[email protected]"
IO(Tcp) ! Connect(new InetSocketAddress("asg.aut.ac.ir", 25))
implicit val timeout = Timeout(new FiniteDuration(100, SECONDS))
val localhost = InetAddress.getLocalHost()
def writeFrom(connection: ActorRef) = {
asker(connection) ? Write(ByteString("MAIL From:<" + from + ">",
"US-ASCII"), NoAck) onComplete {
case Success(ex) => ex match {
case Received(value)=>{
println("from is:"+ value.utf8String)
writeTo(connection)
}
case _=>println("Error ")
}
case Failure(fa) => println("Error Response :" + fa)
}
}
def writeTo(connection: ActorRef) = {
println(ByteString("To:Ehsan uni<"+to+">", "US-ASCII"))
asker(connection) ? Write(ByteString("To:Ehsan uni<"+to+">", "US-ASCII"),
NoAck) onComplete {
case Success(ex) => ex match {
case Received(value)=>{
println("from is:"+ value.utf8String)
}
case _=>println("Error ")
}
case Failure(fa) => println("Error Response :" + fa)
}
}
def receive = {
case CommandFailed(_: Connect) =>
println("connect failed")
context stop self
case Received(data)=>{
println("Received:"+data)
}
case c @ Connected(remote, local) =>
println("Connected" + c)
val connection = sender()
asker(connection) ? Write(ByteString("HELO " + localhost.getHostName(),
"US-ASCII"), NoAck) onComplete {
case Success(ex) => ex match {
case Received(value)=>{
println("value is:"+ value.utf8String)
writeFrom(connection)
}
case _=>println("Error ")
}
case Failure(fa) => println("Error Response" + fa)
}
case x => println("[ERROR] Received" + x)
case Closed=>
println("connection is Closed")
}
}
object RunClient2 extends App{
val system=ActorSystem("ActorTcp")
val net = new InetSocketAddress("asg.aut.ac.ir",25)
val clientTwo=system.actorOf(Props[Client2])
Thread.sleep(300000)
system.terminate()
}
and this my response
ConnectedConnected(asg.aut.ac.ir/194.225.33.10:25,/192.168.17.102:59002)
value is:220 asg.aut.ac.ir ESMTP ready.
ByteString(77, 65, 73, 76, 32, 70, 114, 111, 109, 58, 60, 101, 104, 115, 97,
110, 64, 116, 101, 99, 104, 108, 97, 110, 100, 46, 105, 114, 62)
[INFO] [02/04/2018 22:40:34.330] [Thread-0]
[CoordinatedShutdown(akka://ActorTcp)]
Starting coordinated shutdown from JVM shutdown hook
Error Response :akka.pattern.AskTimeoutException: Ask timed out on [Actor[
akka://ActorTcp/user/$a/0Asker#60133337]] after [100000 ms].
Sender[Actor[akka://ActorTcp/user/$a#132021559]] sent message of type
"akka.io.Tcp$Write".
why when call writeFrom i ve got Error AskTimeoutException
and how can change code to request and response
Correctly and efficiently ???
thanks
--
>>>>>>>>>> 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 https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.