lundi 13 novembre 2017

How to design reconnection logic between server and client?

Reconnection between client and server is done using the initialization, where client sends initial message and gets response from server. This initialization can be repeated many times before connection is established. Client and server communicate through keep-alive connection. There is only 1 client and many servers.

  1. Client can connect to at most 1 server at any given time
  2. Client has server-list, which contains the servers which it can connect to, one of the servers is preferred choice
  3. Client always tries to connect first to the preferred choice, if it can't, it tries to connect to other servers
  4. At start-up, before it first connects, the clients' server-list contains 1 member
  5. When client tries to connect for the first time or reconnect, it sends initial message to server -> 1 of 3 responses is possible -> CHANGE_SERVER, OK, ERROR
  6. CHANGE_SERVER and OK responses will also contain new server-list, which will replace the existing one
  7. OK response -> it means client is connected to the right server and it stays connected
  8. CHANGE_SERVER -> Client succesfully connected to a given server, but it is told to connect to a different one, tries to reconnect
  9. ERROR -> could not connect to a given server, tries a different one
  10. If client was connected and now cannot send a message, then it will try to reconnect
  11. If client is already connected (receiving OK), it does not try to reconnect

I was hoping somebody could help me with designing possible solution to this problem. What I'm looking for is high-level model, with classes and methods (no code of course) or something like that. Some design which would help me to avoid global variables in implementation. I will be using Java for actual implementation. My short research is pointing me in the direction of Actor model and Akka framework.

Aucun commentaire:

Enregistrer un commentaire