Doubt About Socket Logic

1

I have a question regarding identifying socket. Suppose I have 2 "socket types", a client and an attendant. Where is the chat of the 2, I can have several clients and several attendants, but my question is, how to identify each one?

I'm doing the following, but I do not know if it's a good practice or if there are better ways.

I have the class Server, which receives the Socket and instantiates a Class Gerencia_Socket , when receiving the first message, defines if the socket is a client or attendant, if it is a client, it creates an object of type Gerencia_Cliente , where has all the information of the client, if it is listener creates of type Gerencia_Atendente , with the information of the attendant.

Is it feasible to do this? Because I already have 6 classes

  • Servidor
  • Gerencia_Socket
  • Gerencia_Cliente
  • Gerencia_Atendente
  • Atendente (Socket itself)
  • Cliente (Socket itself)

Thank you in advance!

    
asked by anonymous 31.10.2016 / 05:08

1 answer

3

Yes, you can use inherited classes to determine what kind of socket, however in the case you described it might be simpler if you just create two list variables in the server class as follows:

private final List<Gerencia_Socket> atendentes = new ArraysList<>();
private final List<Gerencia_Socket> clientes = new ArraysList<>();

When the socket type is identified, add the corresponding list as follows:

atendentes.add(novoAtendente);

There will only be a need to create other classes if there is any divergent behavior between the sockets, however in the case you have described there is no reason.

    
31.10.2016 / 13:41