V
V
Vitaly Yakovenko2012-06-09 00:12:04
Java
Vitaly Yakovenko, 2012-06-09 00:12:04

By stream per client?

I'm trying to implement a multi-threaded server for a flash game in java.
It is important enough that there are no delays in processing incoming data from the client.
Would it be correct to do it the way it is done in most of the tutorials I found, namely, to create a thread for each client connecting via ServerSocket.accept()? Are there more advanced alternatives to this solution?

Thank you.

Answer the question

In order to leave comments, you need to log in

6 answer(s)
R
relgames, 2012-06-11
@Xazzzi

The latest trend - all sorts of NIO

G
gvsmirnov, 2012-06-09
@gvsmirnov

Creating a thread is not a very cheap operation, therefore, for these purposes, they came up with thread pools that reuse existing threads. In your case, cached thread pool may be suitable .
In general, if you communicate between a flash application and a java server via http, then perhaps instead of using sockets directly, you should look towards ready-made solutions. For example jetty.

T
TheHorse, 2012-06-09
@TheHorse

1. In most cases, the classical approach - 1 thread, synchronous processing - is fast enough. Especially if there are no readings from files and other things.
2. If point 1 is not suitable, there should be a static number of threads, preferably equal to the number of hardware threads (cores) of the processor.
If the theory is interesting - see Moore / Mealy automata, event-oriented approach, if the language - see the previous answer.

M
Maxim Kuzovlev, 2012-06-09
@KY3EH

Look at Netty

W
Wott, 2012-06-09
@Wott

creating or allocating a stream to a client is a classic of client-server applications, but I think that if the game is, then each client will have a permanent two-way connection to the server and you need to look towards server push and other comets.
It seems to me that it is necessary to separate the connection pool and the thread pool of handlers with a message queue.

I
Ilya Plotnikov, 2012-06-09
@fzn7

Look how it's done in Red5, you can learn some knowledge there.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question