Because of this:
making it as concise and short as possible
I can't explain in detail why I did what I'll write below
that bad way.
I have already developed (for quite some time) a client (B4A) - server (B4J-Jetty websocket server) pair for a game, which has been running.
The (bad) "structure" of the client is roughly like this:
(This kind of "structure" forced me to almost duplicate many routines).
Use B4XPages. You will not need to think about such things at all.
I had thought of using B4XPages (also for a possible future B4I-iOS version) but the problem of choosing whether to use a single websocket or one for each game server would remain. Same thing regarding the number, type and "location" of objects.
Additionally, a service module is required; it must contain at least one websocket (or an object that contains the websocket, one of the many doubts) as messages received by the server (or servers) must be received even if the user sends the app to background (home button, incoming phone call, ...).
I'm not sure that you gave us enough information, but as a general rule, if you have 3 connections then the state will be more complicated as you will have cases when one connection breaks while the others still work.
I didn't mean more than one websocket connected simultaneously but one at a time (maybe two, but I'd like to be concise
).
The user chooses a game and the app connects to the related server.
So I might have:
a) 3 "websocket handler" classes, 3 game classes (containing the 3 "websocket handler" instances/object) into the "comunication service module"
b) the 3 game classes containing the "websocket handler" class code directly, still in the service
c) 1 websocket handler class only, in the service, to be connected and disconnected from one server at a time. In this case the message sent by the server should contain a reference/id of the game to which it refers.
Writing and "thinking", maybe the option (c) should be the best (although the code may not be very readable, manageable, updatable, ... ?)
Perfect! I was neither clear nor
concise, as usual ?