Package it.fi.meucci
Class RequestListener
java.lang.Object
it.fi.meucci.RequestListener
- All Implemented Interfaces:
Runnable
The class used to read from the socket's input stream. It handles received messages with proper Handler methods.
-
Field Summary
FieldsModifier and TypeFieldDescriptionbooleanSays whether this instance of Request Listener is allowed to run -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidchangeName(String usr) Changes name if availablevoidHandles the received messageread()Reads from the socket's input streamvoidrun()Thread.run() implementation.voidsendList()Sends to the client a list of connected userstoString()voidSends the message to the output stream
-
Field Details
-
allowedToRun
public boolean allowedToRunSays whether this instance of Request Listener is allowed to run
-
-
Constructor Details
-
RequestListener
- Parameters:
socket- Socket to be handled- Throws:
IOException
-
-
Method Details
-
changeName
Changes name if available- Parameters:
usr- the new username- Throws:
IOException- when it's unable to send errors to the socket's output stream
-
run
public void run()Thread.run() implementation. Starts the communication with a List message and a Need Name Message Catches a bunch of exceptions -
handle
Handles the received message- Parameters:
msg- The message to be handled- Throws:
IOException- when it's impossible to write to the socket's output stream
-
sendList
Sends to the client a list of connected users- Throws:
com.fasterxml.jackson.core.JsonProcessingException- When parsing failsIOException- When writing to the socket's output stream fails
-
write
Sends the message to the output stream- Parameters:
msg- The message to be sent
-
read
Reads from the socket's input stream- Returns:
- The just read message
- Throws:
IOException- When it's impossible to read from the socket's input stream
-
getUsername
- Returns:
- the client's username
-
toString
-