[akka-user] Re: XMPP chat server vs Akka TCP

2017-03-02 Thread livetouch
Hi Johannes,

Thank you for the answer.

On Thursday, February 23, 2017 at 12:45:59 PM UTC-3, Johannes Rudolph wrote:
>
> Hi,
>
> XMPP is an application-level protocol while TCP is a transport-level 
> protocol. In fact, XMPP usually runs *on top of* TCP. So, yes, you can use 
> Akka TCP to implement XMPP.
>
> Comparing XMPP to what you probably have right now is that in your current 
> application you used your own custom protocol the clients use to talk to 
> your chat server. On the other side, XMPP is a standard for a chat protocol 
> that defines how messages should be sent over the wire.
>
> Fwiw it seems that XMPP in fact supports different kinds of transport 
> protocols: 
> https://en.wikipedia.org/wiki/XMPP#XMPP_via_HTTP_and_WebSocket_transports
>
> Cheers,
> Johannes
>
> On Thursday, February 23, 2017 at 3:59:20 PM UTC+1, livetouch wrote:
>>
>> Hi,
>>
>> I have to develop a chat web application + android/ios clients.
>>
>> I did a sample using Akka Actors, using Akka TCP. So I have an 
>> TCPUserActor that receives the connection, and after that I have some 
>> UserActor for each user in the application.
>>
>> But I friend told me that chat applications uses XMPP protocol, and that 
>> some chats like Gmail, Messanger, Whatsapp uses it..
>>
>> So the question is, can I use just Akka TCP for my chat application? Or 
>> XMPP is better for this?
>>
>> Or can I use Akka TCP + XMPP together?
>>
>> thank you
>>
>

-- 
>>>>>>>>>>  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+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.


[akka-user] XMPP chat server vs Akka TCP

2017-02-23 Thread livetouch
Hi,

I have to develop a chat web application + android/ios clients.

I did a sample using Akka Actors, using Akka TCP. So I have an TCPUserActor 
that receives the connection, and after that I have some UserActor for each 
user in the application.

But I friend told me that chat applications uses XMPP protocol, and that 
some chats like Gmail, Messanger, Whatsapp uses it..

So the question is, can I use just Akka TCP for my chat application? Or 
XMPP is better for this?

Or can I use Akka TCP + XMPP together?

thank you

-- 
>>  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+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.


Re: [akka-user] Android chat

2016-03-15 Thread livetouch
Thanks, I´ll try it.

On Friday, March 11, 2016 at 10:29:34 AM UTC-3, Akka Team wrote:
>
> Hi,
>
> To notice that you lost contact with the other end of a TCP socket you 
> have to read or write the socket, this is probably best achieved by 
> providing some type of heartbeat in your own protocol.
>
> --
> Johan Andrén
> Akka Team, Lightbend Inc.
>

-- 
>>  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+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.


[akka-user] Android chat

2016-03-08 Thread livetouch
Hi all,

I am using Akka to create a chat application.

I start the TCP socket using StartTcpConnectionActor and after a new 
connnetion is established I start the TcpConnectionActor for each 
connnection.

My android client, uses the Socket class to connect to the server and 
everything works ok.

But I have some problems to finish the connection.

In my client, if I call socket.close() , I receive Tcp.PeerClosed on my 
server, so I can finish the connection.

But if the user turn Off the Wifi on his device, the server didn´t receive 
any error. 

The onReceive() method on my TcpConnectionActor is not even called.. So in 
my server, Akka doesnt know that my user is offline without any Wifi 
connection...

Is this the expected behavior? If the device turns the Wifi Off, it should 
break the socket connection, or not?

thank you

-- 
>>  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+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.
package br.livetouch.livecom.chatAkka.actor;

import java.net.InetSocketAddress;

import org.apache.log4j.Logger;

import akka.actor.ActorRef;
import akka.actor.Props;
import akka.actor.UntypedActor;
import akka.io.Tcp;
import akka.io.TcpMessage;
import br.infra.util.Log;

public class StartTcpConnectionActor extends UntypedActor {

	private static Logger log = Log.getLogger("TcpConnectionActor");

	public static class Start {
		public int port;

		public Start(int port) {
			this.port = port;
		}
	}

	@Override
	public void onReceive(Object msg) throws Exception {
		if (msg instanceof Start) {
			// Faz start do AKKA server
			log.debug("Akka Server - Bind to socket:" + ((Start) msg).port);
			final ActorRef tcp = Tcp.get(getContext().system()).manager();

			tcp.tell(TcpMessage.bind(getSelf(), new InetSocketAddress(((Start) msg).port), 100), getSelf());

		} else if (msg instanceof Tcp.Connected) {
			// Cliente conectou o socket
			log.error("Akka Server - Ator conectado: " + getSender());
			
			// Cria o ator para leitura TCP do Socket
			ActorRef tcpUserActor = getContext().actorOf(Props.create(TcpConnectionActor.class, getSender()));

			ActorRef connectionActor = getSender();
			connectionActor.tell(TcpMessage.register(tcpUserActor), getSelf());
		} else if (msg instanceof Tcp.CommandFailed) {
			log.error("Akka Server - Error to bind to port");
			getContext().stop(self());
		} else {
			log.error("StartTcpConnectionActor ERROR! " + msg);
			System.err.println("StartTcpConnectionActor ERROR! " + msg);
		}
	}
}
package br.livetouch.livecom.chatAkka.actor;

import java.io.UnsupportedEncodingException;

import org.apache.log4j.Logger;

import akka.actor.ActorRef;
import akka.actor.ActorSelection;
import akka.actor.UntypedActor;
import akka.io.Tcp;
import akka.io.Tcp.Received;
import akka.io.Tcp.Write;
import akka.util.ByteString;
import br.infra.util.Log;
import br.livetouch.livecom.chatAkka.actor.UserActor.Stop;
import br.livetouch.livecom.chatAkka.protocol.AkkaJson;
import br.livetouch.livecom.chatAkka.protocol.JsonRawMessage;
import br.livetouch.livecom.chatAkka.protocol.RawMessage;

/**
 * Ator para escrever no socket.
 * 
 * Faz o loop de leitura das mensagens e envia pro UserMessageRouter
 * 
 * @author rlech
 *
 */
public class TcpConnectionActor extends UntypedActor {

	private static Logger log = Log.getLogger("TcpConnectionActor");

	public enum State {
		Idle, StartReadHeader, StartReadMsg;
	}

	private boolean continueToReadSplitMessage = false;
	private ByteString msgPartsContinue = null;
	private int sizeContinue = 0;
	private int totalBytesReaded = 0;

	public ActorSelection userMessageRouter;
	/**
	 * UserActor criado quando fez a conexão TCP.
	 * É o UserActor que contém várias conexões.
	 */
	public ActorRef userActorWhenLogged;
	public Long userId;
	public String userSo;

	/**
	 * Ator da conexão. Contém o socket para escrever.
	 */
	public ActorRef tcpConnection;
	private int nextPercent;

	/**
	 * Construtor chamado por reflexão
	 * 
	 * @param connection
	 */
	public TcpConnectionActor(ActorRef connection) {
		this.tcpConnection = connection;
	}

	@Override
	public void preStart() throws Exception {
		userMessageRouter = AkkaFactory.getUserMessageRouter(getContext());
		super.preStart();
	}

	@Override
	public void onReceive(Object msg) throws Exception {
		try {
			if (msg instanceof Received) {

ByteString data = ((Received) msg).data();
receiveData(data);
return;

			} else if (msg instanceof