|
Crossfire JXClient, Trunk
|
Inheritance diagram for ChatServer:
Collaboration diagram for ChatServer:Public Member Functions | |
| ChatServer (int port) throws IOException | |
| SocketAddress | getSocketAddress () throws IOException |
| void | removeClient (Client client) |
| void | run () |
| void | shutdown () throws InterruptedException, IOException |
| void | writeMessageToClients (Client client, String message) |
Static Public Member Functions | |
| static void | main (String[] args) throws IOException |
Private Member Functions | |
| AsynchronousServerSocketChannel | createListener (AsynchronousChannelGroup channelGroup) throws IOException |
| void | handleNewConnection (AsynchronousSocketChannel channel) |
| AsynchronousServerSocketChannel | openChannel (AsynchronousChannelGroup channelGroup) throws IOException |
Static Private Member Functions | |
| static void | usage () |
Private Attributes | |
| final AsynchronousChannelGroup | channelGroup |
| final List< Client > | connections = Collections.synchronizedList(new ArrayList<Client>()) |
| final AsynchronousServerSocketChannel | listener |
| int | port |
Implements a chat server, this class holds the list of
connected to the server. It sets up a server socket using AsynchronousServerSocketChannel listening to a specified port.
Definition at line 54 of file ChatServer.java.
| ChatServer.ChatServer | ( | int | port | ) | throws IOException |
| port | to listen to |
| java.io.IOException | when failing to start the server |
Definition at line 65 of file ChatServer.java.
References channelGroup, createListener(), listener, and port.
Referenced by main().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Definition at line 115 of file ChatServer.java.
References channelGroup, listener, openChannel(), and port.
Referenced by ChatServer().
Here is the call graph for this function:
Here is the caller graph for this function:| SocketAddress ChatServer.getSocketAddress | ( | ) | throws IOException |
| java.io.IOException | if an I/O error occurs |
Definition at line 77 of file ChatServer.java.
References listener.
|
private |
Creates a new client and adds it to the list of connections. Sets the clients handler to the initial state of NameReader
| channel | the newly accepted channel |
Definition at line 132 of file ChatServer.java.
References connections.
Referenced by run().
Here is the caller graph for this function:
|
static |
Definition at line 170 of file ChatServer.java.
References ChatServer(), port, and usage().
Here is the call graph for this function:
|
private |
Definition at line 122 of file ChatServer.java.
References channelGroup.
Referenced by createListener().
Here is the caller graph for this function:| void ChatServer.removeClient | ( | Client | client | ) |
Definition at line 161 of file ChatServer.java.
References connections.
| void ChatServer.run | ( | ) |
Start accepting connections
Definition at line 84 of file ChatServer.java.
References handleNewConnection(), and listener.
Here is the call graph for this function:| void ChatServer.shutdown | ( | ) | throws InterruptedException, IOException |
Shuts down the server
| InterruptedException | if terminated while waiting for shutdown |
| IOException | if failing to shutdown the channel group |
Definition at line 107 of file ChatServer.java.
References channelGroup.
|
staticprivate |
Definition at line 165 of file ChatServer.java.
Referenced by main().
Here is the caller graph for this function:| void ChatServer.writeMessageToClients | ( | Client | client, |
| String | message | ||
| ) |
Sends a message to all clients except the source. The method is synchronized as it is desired that messages are sent to all clients in the same order as received.
| client | the message source |
| message | the message to be sent |
Definition at line 151 of file ChatServer.java.
References connections.
|
private |
Definition at line 58 of file ChatServer.java.
Referenced by ChatServer(), createListener(), openChannel(), and shutdown().
|
private |
Definition at line 55 of file ChatServer.java.
Referenced by handleNewConnection(), removeClient(), and writeMessageToClients().
|
private |
Definition at line 57 of file ChatServer.java.
Referenced by ChatServer(), createListener(), getSocketAddress(), and run().
|
private |
Definition at line 56 of file ChatServer.java.
Referenced by ChatServer(), createListener(), and main().