Crossfire JXClient, Trunk
Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
NameReader Class Reference
Inheritance diagram for NameReader:
Inheritance graph
Collaboration diagram for NameReader:
Collaboration graph

Public Member Functions

boolean acceptsMessages ()
 
void beforeRead (Client client)
 
 NameReader (ChatServer chatServer)
 
void onData (Client client, ByteBuffer buffer, int bytes)
 

Private Member Functions

void onUserNameRead (Client client, String name)
 
void sendRemainingParts (Client client, String[] strings)
 

Private Attributes

final StringBuilder buffer = new StringBuilder()
 
final ChatServer chatServer
 
boolean once = true
 

Static Private Attributes

static final String NEWLINE = "\n"
 

Detailed Description

The first state a newly connected

is in, this handles writing out the welcoming message and reads the response up to a newline. When a newline character have been received it changes the handler from NameReader to MessageReader on the client.

Definition at line 50 of file NameReader.java.

Constructor & Destructor Documentation

◆ NameReader()

NameReader.NameReader ( ChatServer  chatServer)

Definition at line 56 of file NameReader.java.

References chatServer.

Member Function Documentation

◆ acceptsMessages()

boolean NameReader.acceptsMessages ( )

Implements DataReader.

Definition at line 75 of file NameReader.java.

◆ beforeRead()

void NameReader.beforeRead ( Client  client)

Writes the welcoming message to the client the first time this method is called.

Parameters
clientthe client to receive the message

Implements DataReader.

Definition at line 67 of file NameReader.java.

References client, and once.

◆ onData()

void NameReader.onData ( Client  client,
ByteBuffer  buffer,
int  bytes 
)

Receives incoming data from the socket, searches for a newline and tries to set the username if one is found

Implements DataReader.

Definition at line 84 of file NameReader.java.

References buffer, client, name(), NEWLINE, and onUserNameRead().

Here is the call graph for this function:

◆ onUserNameRead()

void NameReader.onUserNameRead ( Client  client,
String  name 
)
private

Splits the name on the newlines, takes the first as the username and appends everything else to the clients message buffer. Sets the clients handler to MessageReader.

Parameters
clientthe client to set the username for
namethe string containing the buffered input

Definition at line 101 of file NameReader.java.

References chatServer, client, name(), NEWLINE, and sendRemainingParts().

Referenced by onData().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sendRemainingParts()

void NameReader.sendRemainingParts ( Client  client,
String[]  strings 
)
private

Appends the remaining parts to the clients message buffer

Parameters
clientthe client
stringsthe messages to append to the buffer

Definition at line 115 of file NameReader.java.

References client.

Referenced by onUserNameRead().

Here is the caller graph for this function:

Member Data Documentation

◆ buffer

final StringBuilder NameReader.buffer = new StringBuilder()
private

Definition at line 51 of file NameReader.java.

Referenced by onData().

◆ chatServer

final ChatServer NameReader.chatServer
private

Definition at line 52 of file NameReader.java.

Referenced by NameReader(), and onUserNameRead().

◆ NEWLINE

final String NameReader.NEWLINE = "\n"
staticprivate

Definition at line 54 of file NameReader.java.

Referenced by onData(), and onUserNameRead().

◆ once

boolean NameReader.once = true
private

Definition at line 53 of file NameReader.java.

Referenced by beforeRead().


The documentation for this class was generated from the following file:
Client
Definition: Client.java:59