Have i implemented this right?

Ive added some networking to a 2D game of mine and basically read a simple serversocket and socket tutorial and just went from there without any other knowledge, i just wanted to make sure im not doing it a really long badly drawn out way.

The server loops round with the ol’ somesocket = serversocket.accept(); in a while loop waiting for clients, once its caught one it stores it in a static array of sockets then creates a new thread to communicate with the client.
This Thread then creates a BufferedReader and PrintStream for the socket that was passed to it sends the map data to client once then for the rest of its life it then just listens for x,y of player to be sent to that socket and reads it when it is and stores it in a static array of xy integers in another class(the one this all started from).
In the main server Thread its in a while loop which sleeps 12 milli everytime in this while loop it repaints the window to display some info, its a JFrame btw and also calls a sendToAll() meathod which sends all xy’s, out to all players using the static arrays of xy cords and sockets mentioned earlier, it has to create a new printstream everytime it does this.

Client side when the game loads the static meathod load in the loadMap class is called which creates a new static socket and trys to connect to the server, then it creates a bufferedReader and gets ye olde map. Then the game continues running.
Everytime player.move() is called in the main gameLoop it creates a new threads which creates a printstream from the static socket in the loadMap class and sends the xy to server.
Then every time the gameloops a getPlayerPostitions meathod is called directly from the loop which gets the x,y’s of all players.

Are the static sockets a good thing? should i be doing this a diffrent way? seems to be working atm and not lagging but thats on local host and i havent actually added anything to the clients yet to draw the other players with the recived x, y’s.

tl;dr good server architecture to 2D game

Sounds about right. If you have any real doubts, post some code since that is more helpful that a vague description :slight_smile:

Well I have no idea what kind of game this is - moving in a board game is a lot different than moving a character in a 2D platformer for example.

[quote]Everytime player.move() is called in the main gameLoop it creates a new threads which creates a printstream from the static socket in the loadMap class and sends the xy to server.
[/quote]
that sounds a little off

Oh yeah, I must have overlooked that part.
@OP
Don’t created a lot of threads, what you do is create 1 thread per client and let it run in a loop receiving commands and replying.

Now, dont punch me for suggesting NIO if you have more than 50 players. There is libraries that is simpler to use than standard I/O, and uses nio. Kryonet, for instance.