How can I keep a connection active to OpenFire?

Hi,

I am currently testing the Smack API with an OpenFire server.

I would like to make use of this API within a Web Application.

When calling a connection to the jabber server, from my web client, my web application server makes the connection to OpenFire reads message, sends message etc… But the connection is never kept ‘‘alive’’. This makes my users appear and disapear online & offline each time an action is performed!

How could I keep this connection ‘‘connected’’, knowing that end users are in a web browser?

I would personally separate the front-end application (the web UI) from the back-end. Then I would create either a session unique-id key that is kept in the client’'s browser to identify itself (it could also be a cookie).

On the back-end, I would match that session id with a static XMPPConnection object stored in a Hashtable.

That would result in having a sort of connection pool binded to each client connecting through the web interface.

Actually, Smack would allow you to have a few pending connections that would be missing the login part. That is commonly used in database to save ALOT of time to execute database query. Read on wikipedia about connection pools and how they can be used for web applications. I think this would be the best scenario, maybe someone else can confirm ?

1 Like

All right, so I should write a pool manager that would be always running as a servlet on my application server?

As for disconnecting users, either they disconnect theselves with a special link that calls the logoff, either I test for inactivity on the pool on a regular basis?

I think this is the best approach.

Your disconnection schema is also very good.