Using sockets to make data requests

0

I have a mental problem on this subject because I do not know about patterns or best practices that fulfill this task (please, enlighten me on this subject).

My context is the following, using Sockets (concretely java.net.Socket and java.net.SocketServer ) I have a client that makes requests to a server. These requests can be of different types (imagine a hypothetical class called peticion from which different subclasses inherit), so the server has different methods declared to collect the information, depending on the type of the request. This information is treated through the implementation of REST, Jersey, the purpose of the requests is only to cause the execution of methods on the server to update the REST server information.

My problem is that I do not know how to differentiate the types of requests that arrive at the server and, according to this one, execute one method or another to update the information.

The custiones are as follows : is it a bad design if in the request class I set a variable String called tipoPeticion to help me process those requests? If not, what is the correct form? Is this defined in a pattern? Am I wrong and am I wrong?

They can answer any of the questions, but the one that would interest me the most is the second one.

I'm delighted to edit the thread if you think it's formulated!

    
asked by JD0001 22.06.2017 в 19:14
source

2 answers

0

Creating a variable to save the type of request is a good option. Then you add the contents of this variable to the request that you make to your server with the rest of the data, and it is already programmed in the server so that it discriminates the type of request and according to which it receives, it processes it in one way or another.

    
answered by 22.06.2017 в 22:11
0

Since you have to perform different actions according to the request, I think it would be best to use a pattern of commands , this presentation can serve you .

    
answered by 23.06.2017 в 04:59