0

I am searching for a Java library (or a simple class) that is able to manage server sessions for any protocol. My application is not related in any way to HTTP. The sessions have to stay alive between different connections, just like HTTP cookies do.

I guess the way to go is:

  1. client connects to server
  2. client sends the login informations
  3. server replies with a status and a session ID (a long string, just like JSESSIONID or PHPSESSID)
  4. client sends requests to server (with existing or new TCP connections), always providing the session ID
  5. client asks to logout
  6. server deletes the session and invalidates the session ID

I'm just looking for something existing regarding the session management part, even if it's really easy to implement. Otherwise I guess a Map and a random string generator will do the job.

eepp
  • 7,255
  • 1
  • 38
  • 56
  • 2
    I would rather use a sessionmanagement table in database for your requirement which is rather simple than to use a library for this. – Tito Dec 09 '12 at 05:11

2 Answers2

0

http://docs.oracle.com/javase/1.5.0/docs/api/java/util/UUID.html#randomUUID%28%29

http://www.javapractices.com/topic/TopicAction.do?Id=56

randomUUID() method could be useful in java.util.UUID see above links. It guarantees the id is unique.

user1888773
  • 144
  • 2
0

If you want to make your session data to be scaled across multiple nodes, you can even try out frameworks like hazelcast, infinispan etc. They also have a provision to generate unique id across nodes.

CuriousMind
  • 3,143
  • 3
  • 29
  • 54