• Home
  • History
  • Annotate
  • only in /prebuilts/jdk/jdk8/linux-x86/sample/nio/chatserver/
NameDateSize

..10-Aug-20184 KiB

ChatServer.java10-Aug-20186.9 KiB

Client.java10-Aug-20186.6 KiB

ClientReader.java10-Aug-20183.5 KiB

DataReader.java10-Aug-20182.1 KiB

MessageReader.java10-Aug-20183.2 KiB

NameReader.java10-Aug-20184.5 KiB

README.txt10-Aug-20182 KiB

README.txt

1A Simple Chat Server Example
2
3INTRODUCTION
4============
5This directory contains a very simple chat server, the server takes input from a
6socket ("user") and sends it to all other connected sockets ("users") along with
7the provided name the user was asked for when first connecting.
8
9The server was written to demonstrate the asynchronous I/O API in JDK 7. 
10The sample assumes the reader has some familiarity with the subject matter.
11
12SETUP
13=====
14
15The server must be built with version 7 (or later) of the JDK.
16The server is built with:
17
18    % mkdir build
19    % javac -source 7 -target 7 -d build *.java
20
21EXECUTION
22=========
23
24    % java -classpath build ChatServer [-port <port number>]
25
26    Usage:  ChatServer [options]
27        options:
28            -port port      port number
29                default: 5000
30
31CLIENT EXECUTION
32================
33
34No client binary is included in the sample.
35Connections can be made using for example the telnet command or any program
36that supports a raw TCP connection to a port.
37
38SOURCE CODE OVERVIEW
39====================
40ChatServer is the main class, it handles the startup and handles incoming
41connections on the listening sockets. It keeps a list of connected client
42and provides methods for sending a message to them.
43
44Client represents a connected user, it provides methods for reading/writing
45from/to the underlying socket. It also contains a buffer of input read from
46the user.
47
48DataReader provides the interface of the two states a user can
49be in. Waiting for a name (and not receiving any messages while doing so, implemented
50by NameReader) and waiting for messages from the user (implemented by MessageReader).
51
52ClientReader contains the "main loop" for a connected client. 
53
54NameReader is the initial state for a new client, it sends the user a string and
55waits for a response before changing the state to MessageReader.
56
57MessageReader is the main state for a client, it checks for new messages to send to
58other clients and reads messages from the client.
59
60FINALLY
61=======
62This is a sample: it is not production quality and isn't optimized for performance.
63