So, I’ve decided before I start working on my next game that it will have multiplayer capabilities. There will be a server which the client connects to. The client will connect to the server almost constantly, and will handle things like rendering and user input while the server handles everything else. This includes (but is not limited to) entity location, map models/textures to be downloaded, player location/items/health/etc, and one server-tick will be every 1/16th of a second. However, I ran into an issue in the very beginning…
The server waits for a client to connect and request information before continuing through its loop to do everything else. I tried to fix this by using a ServerSocketChannel with configureBlocking set to false instead of using a ServerSocket, however this requires information to be sent/received through the use of ByteBuffers. This wouldn’t be an issue, however I won’t always know the exact amount of information and bytes that will be sent/recieved, so they don’t really work out too well. I’ve been thinking I could try multi-threading, however I’ve never done this before.
tl;dr My questions shortened and paraphrased:
How do I get my server to loop through and handle game-logic while accepting user input at the same time? Should I use multi-threading?
How would YOU write a game-server? (for example, how would you handle client requesting information/server sending information?)
I am completely new to the world of networking. I’ve been programming for years yet never gotten into it. Sorry if I sound completely new to all this, because I am!