Crossfire JXClient, Trunk
|
Go to the documentation of this file.
41 import java.nio.ByteBuffer;
51 private final StringBuilder
buffer =
new StringBuilder();
53 private boolean once =
true;
54 private static final String
NEWLINE =
"\n";
70 client.writeStringMessage(
"Name: ");
87 name = this.buffer.append(
new String(
buffer.array(), 0, bytes)).toString();
103 client.setUserName(strings[0].trim());
106 client.writeStringMessage(
"Welcome " +
client.getUserName() +
"\n");
116 for (
int i = 1; i < strings.length; ++i) {
117 client.appendMessage(strings[i]);
NameReader(ChatServer chatServer)
static final String NEWLINE
void sendRemainingParts(Client client, String[] strings)
void beforeRead(Client client)
void onUserNameRead(Client client, String name)
void onData(Client client, ByteBuffer buffer, int bytes)
final StringBuilder buffer
boolean acceptsMessages()
A Simple Chat Server Example the server takes input from a it handles the startup and handles incoming connections on the listening sockets It keeps a list of connected client and provides methods for sending a message to them Client represents a connected it provides methods for reading writing from to the underlying socket It also contains a buffer of input read from the user DataReader provides the interface of the two states a user can be in Waiting for a it sends the user a string and waits for a response before changing the state to MessageReader MessageReader is the main state for a client
final ChatServer chatServer
A Simple Chat Server Example the server takes input from a it handles the startup and handles incoming connections on the listening sockets It keeps a list of connected client and provides methods for sending a message to them Client represents a connected it provides methods for reading writing from to the underlying socket It also contains a buffer of input read from the user DataReader provides the interface of the two states a user can be in Waiting for a name(and not receiving any messages while doing so, implemented by NameReader) and waiting for messages from the user(implemented by MessageReader). ClientReader contains the "main loop" for a connected client. NameReader is the initial state for a new client