M
M
Meridian3122014-06-14 17:52:31
Java
Meridian312, 2014-06-14 17:52:31

How to organize the work of a multi-threaded server in Java?

I am just starting to learn multitasking and parallel programming in Java. My task is to create a simple server for transferring file messages between clients, respectively.

I want to know how can I better organize the processing of sockets and data on the server?

I would like to create some kind of list of socket clients or their handlers (threads), if at all possible, and then forward data to specific sockets accordingly. Or is it better for me to have links to all connections to the server, while each dead connection itself is removed from the list?

The main problem is that now I have to describe the scripts for the objects passed through the socket
i.e. as in.readObject() instanceof User then a specific response scenario. But I wanted to somehow associate each new file sender with a specific user on the server.

I apologize for not being clear, because I just don't know how to formulate a direct question.
Thanks

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Cheremisin, 2014-06-14
@leahch

You need user sessions, I don't know how they will be implemented in your specific application. But it is possible through the transfer to the client of a certain generated key of the uuid type, or over an open socket (for example, a bunch of ip / port), the whole point is how the client interacts with the server. Further, in order not to bother with sockets and streams, it is better to use a ready-made framework like netty.io

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question