E
E
Ernest Farukshin2020-02-20 21:28:41
Java
Ernest Farukshin, 2020-02-20 21:28:41

How to store connections (Socket) of clients and whether it is necessary to do it?

I am writing a messenger, and as I understand it, I need to store each connection (Socket) of the client somewhere on the server (Let's say if the client receives a letter, I will have to somehow find its connection on the server and send a message). I thought to store the Login-Socket value in the Map in order to know where whose connection is. Or is it better to store it somehow differently, or does it not need to be stored at all?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vamp, 2020-02-21
@Ernest3

Of course, you need to store the object, otherwise how can the client send data?
Start with Map, and then we'll see. You also need to ensure that the Map is regularly cleared of closed sockets, otherwise you will get a memory leak.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question