xmppframework - How to manage XMPP connection -
i designing chat application using ejabberd xmpp server , smack 4.1 api. below code snippet managing connection.
// create connection server.com server on 5222 port. xmpptcpconnectionconfiguration config = xmpptcpconnectionconfiguration.builder() .setusernameandpassword("user", "password") .setservicename("server.com") .sethost("server.com_ip") .setport(5222) .setsecuritymode(securitymode.disabled) .build(); xmpptcpconnection conn = new xmpptcpconnection(config); try { conn.connect(); system.out.println("connection established."); conn.login(); system.out.println("logged in."); } catch (smackexception | ioexception | xmppexception e) { system.out.println("connection not established: " + e.getmessage()); }
some processing chat , muc.
// disconnect conn.disconnect(); system.out.println("connection closed.");
my requirement:
- once user logs app, might not log out months @ time. way whatsapp works.
my question is:
- is idea keep connection open long user logged in?
- if not idea open , close connection every chat message?
need suggestion:
- what efficient way handle connection xmpp server?
although question different, this so answered might (comments too), in nutshell:
opening , closing connection each , every message not should do.
regarding keeping connection idle (like whatsapp), it's 1 of options (look services), other connect when application comes , stay connected long it's up, , use push notifications when app not running.
another option combination of both (more close whatapp does).
hope helps.
Comments
Post a Comment