Question

Since last week iam trying building an multiplayer game. iam statring with a little tictactoe game. I made a simple socket connection between server and client. On the server side iam making 2 thread for each connection. - readThread and writerThread Now whats the best way sending commands to server and put them to ressource whos needing them. iam thing about the strategy pattern, but is this the right scenario? The command i sended to the server should calling another component on the server. example

public abstract class Command {
abstract void execute();
}

public class LoginCommand extends Command{
ServerMethodeInterface serverMethodeInterface;
private String name;
private String passwort;

LoginCommand(String name, String password){
this.name = name;
this.passwort = password;
}

@Override
void execute() {
serverMethodeInterface.login(name,password);
}

}
Was it helpful?

Solution

For modern client-server application such as this game (which doesn't really require 100% "real-time" communication) I'd suggest utilizing the HTTP (Websockets would be perfect) protocol at first, which will give you enough flexibility with proven stability & solidity for the communication itself.
Specific technology would be Spring for example.

On top of that I'd implement the Facade pattern which exposes your server's functionality to your client app in one unified "layer".

From there you could certainly use the Strategy pattern you're considering.

That said as a general suggestion for this particular requirement, of course there are other nice ways.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top