how can write and read async with socket (councurent) ?

64 views
Skip to first unread message

techlan...@gmail.com

unread,
Sep 2, 2017, 7:23:20 AM9/2/17
to Akka User List
hi every one
I'm using akka 2.5.x how can call Socket async for read and write ?(what is the best solution)
i need many connection concurrency for send email this is sample code java ?
public boolean sendEmail(String data, String from, String to,String subject)
throws IOException {
Socket socket;
InputStream inn;
OutputStream outt;
BufferedReader msg;
socket = new Socket(mailHost, SMTP_PORT);
if (socket == null) {
return false;
}
inn = socket.getInputStream();
outt = socket.getOutputStream();
in = new BufferedReader(new InputStreamReader(inn));
out = new PrintWriter(new OutputStreamWriter(outt), true);
if (inn == null || outt == null) {
log("Failed to open streams to socket.");
return false;
}
String initialID = in.readLine();
out.println("HELO " + localhost.getHostName());
String welcome = in.readLine();
out.println("MAIL From:<" + from + ">");
String senderOK = in.readLine();
out.println("RCPT TO:<" + to + ">");
String recipientOK = in.readLine();
out.println("DATA");
out.println("From:Ehsan test<"+from+">");
out.println("To:Ehsan uni<"+to+">");
out.println("Cc:khodam <"+to+">");
out.println("Subject:"+subject);
Date d=new Date();
out.println("Date:"+d.toString());
// this body of email
out.println(data);
out.println(".");
// end of email
String acceptedOK = in.readLine();
out.println("QUIT");
return true;
}
}
how can implement with akka ?
how can write and read async ?
could help me for this solution


Message has been deleted

techlan...@gmail.com

unread,
Sep 4, 2017, 9:46:42 AM9/4/17
to Akka User List
i can use TcpIO or Stream which better ? for above solution  

tech land

unread,
Sep 12, 2017, 4:16:25 AM9/12/17
to akka...@googlegroups.com
can any help me to choose ?

On Mon, Sep 4, 2017 at 9:46 AM, <techlan...@gmail.com> wrote:
i can use TcpIO or Stream which better ? for above solution  

--
>>>>>>>>>> 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 a topic in the Google Groups "Akka User List" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/akka-user/x561vRm6ZhA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to akka-user+unsubscribe@googlegroups.com.
To post to this group, send email to akka...@googlegroups.com.
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

techlan...@gmail.com

unread,
Sep 13, 2017, 10:01:05 AM9/13/17
to Akka User List
Someone who can help me ???

Akka Team

unread,
Sep 14, 2017, 9:13:39 AM9/14/17
to Akka User List
The Akka IO API is actor based and a bit more low level, requiring more boilerplate, the streams one is a higher level API which fits some problems (and mindsets) very well. Performance will likely not differ much so try both and use the one you find easiest to understand and achieve what you want with.

--
Johan
Akka Team

--
>>>>>>>>>> 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 akka-user+unsubscribe@googlegroups.com.

tech land

unread,
Sep 20, 2017, 6:14:12 AM9/20/17
to akka...@googlegroups.com
And question this ?
how i can write 'socket.write' asynchronously
I must use the Future:
for example :
  Fututr{ socket.write(ByteString(date.toString("yy/MM/dd")) ++ EOL)} And get callback ? 
Or not It is not necessary and itself asynchronusly?
-----------------------
To unsubscribe from this group and stop receiving emails from it, send an email to akka-user+...@googlegroups.com.

To post to this group, send email to akka...@googlegroups.com.
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

--
>>>>>>>>>> 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 a topic in the Google Groups "Akka User List" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/akka-user/x561vRm6ZhA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to akka-user+...@googlegroups.com.

Johan Andrén

unread,
Sep 22, 2017, 2:16:50 AM9/22/17
to Akka User List
You can see samples of the two APIs in the docs here:

Actor based API:

Stream based API:

If you are looking for info how to use the Java NIO APIs that is better sought after elsewhere.

--
Johan
Akka Team

To unsubscribe from this group and stop receiving emails from it, send an email to akka-user+unsubscribe@googlegroups.com.

To post to this group, send email to akka...@googlegroups.com.
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

--
>>>>>>>>>> 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 a topic in the Google Groups "Akka User List" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/akka-user/x561vRm6ZhA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to akka-user+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages