I am programming an Android multiplayer game that basically consists of a server on which clients connect and exchange messages. When a player connects to the server, the list of players returns to him. Then the player can select the user to call - of course, he must select the player from the list of players, which contains only connected users.
When player1 challenges player2, the message must be sent from player1 to the server, which in turn should send a message to player2, notifying him of the call. Player2 can accept / reject the call.
I can use the following methods to make this happen:
Use a custom server / client with Java socket programming. The server basically accepts a connection to the client, creating a new stream for each connected client. The problem with this:
- There must be a permanent connection, open from the client to the server, losing the battery life of the Android phone. This is not a very big limitation, since the battery is not consumed so much.
- When I want to develop another game, I will have to rewrite the client / server code from scratch - also choosing a different port to listen for incoming connections - the whole concept becomes quite difficult to maintain.
- I am also worried if this is the way to do it. Ignoring another topic for each client sounds pretty much if thousands of clients connect at the same time. But I guess that computer games do that. Not sure about android.
Use Java REST jerseys to build a client server on top of HTTP. This would be ideal if the server could easily send notifications to clients. There are several design solutions here:
- the client pulls out the server for any new data / notifications every few seconds - this is really bad, because we are stuck with non-response, delay, etc.
- the client can send a wait request to the server, so the client receives a response only after some data becomes available. This is better, but it can still cause a delay when the user needs to send two notifications one by one. The first notification is sent instantly, as the client has already opened a connection, waiting for data to be received. But we will have to wait until the client initiates another long HTTP request to receive a second notification. The problem grows because there are several notifications that need to be sent in a row to a specific client.
- the client can initiate a streaming HTTP message when the connection remains open while processing the request, so the server can also send several messages to the client when it wants. The problem here is that I don't know how well this works on Android. I reviewed several implementations:
- Java jersey + atmosphere: failed to actually get it to work. This seems the most promising, but I donβt want to spend too much time on him, since Iβm not even sure that he is doing what I want.
- Deacon: It seems pretty neat, but after watching the video tutorial on their official web page, I'm not sure that he can do what I need. When player1 challenges player2, can he send a notification to player2 letting him know about the match request?
I would be happy to know how other multiplayer games handle network communications if two players play the game over the network.
I am also opening a completely new proposal on how to achieve what I want. I can encode a lot of things, so feel free to tell me about a more complex way to achieve network communication.
Let me also mention that I will be happy to implement a very specific method for working in my case, so that may be all that will make this work, but I also consider a more general way of communication between clients and server. So that I can program the interface / independently and reuse the code in other Android games, Android applications.
Hope I submitted a problem and I will get some valuable answers.
thanks
source share