Writing a multithreaded Socket Server
This example demonstrates the creation of a multithreaded
socket server application. The server is currently a simple Echo Server, which
simply accepts what the client says and sends it back. The example demonstrates
the basic infrastructure for a true multithreaded server application and can be
directly enhanced to perform as any server application.
The EchoServer accepts multiple client connections and is
capable of serving them simultaneously. It uses a new thread to service every
new client, which allows it to accepts new clients even before all clients are
serviced. The server also identifies each client connection with a unique ID,
making it easy to identify clients if required.
The EchoServer only understands one command, “quit”. On
receiving this command, it quits the thread servicing the client and closes the
connections. Also worth noting are the various places where anetwork connection
could fail. All conditions are handled gracefully by EchoServer, thus making
sure that the server never leaves behind residual threads and that the client is
not capable of crashing the server.
|
|||||
Example Code: | |||||
| |||||
Demonstration: | |||||
|
2012년 1월 5일 목요일
Writing a multithreaded Socket Server
출처 : http://www.javareference.com/jrexamples/viewexample.jsp?id=47
피드 구독하기:
댓글 (Atom)
댓글 없음:
댓글 쓰기