Doubt About Socket logic

Asked

Viewed 57 times

1

I have a question regarding identifying socket. Let’s assume I have 2 "socket types", a customer and an attendant. Where the 2 chat is done, I can have several clients and several attendants, but my question is, how to identify each one?

I’m doing it this way, but I don’t know if it’s good practice or if there are better ways.

I have the Server class, which receives the Socket and instance a Class Gerencia_Socket, when receiving the first message, defines if the socket is a client or attendant, if it is a client, creates an object of type Gerencia_Cliente, where you have all the customer information, if you are an attendant 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 himself)
  • Cliente (Socket himself)

Thank you in advance !

1 answer

3


Yes, you can use inherited classes to determine what type of socket, but 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<>();

Once 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 some divergent behavior between the sockets, but in the case you described there is no reason.

  • Thank you for the reply :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.