lundi 10 octobre 2016

Client/Server design pattern

I am new in programming and I want to code a simple Client Server System where the Client sends commands like "SAY house" and the Server detects the keyword "SAY" as an command and returns whatever is after the keyword (in this case "house"). There are many examples how to do this but what I also want to learn with this project is a good design pattern for problems like this. I dont want to implement everything in only 2 classes like Server.java and Client.java.

So I started with a Server class who starts the server on a port and waits for clients. When he get a Request from a client, the Server class delegates the input to a class "RequestHandler". This class does the switch-case part to detect a command like "Say" or "SHUTDOWN" and calls over an interface the corresponding method.

Is this a good pattern? The problem is for example the service "SHUTDOWN". I have to take the Socket Object all along with me to the method who executes the command. Or maybe this pattern isnt good for upgrading the Server with more Functions? Help please for improvements!

Thanks

Aucun commentaire:

Enregistrer un commentaire