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
Modifier and TypeFieldDescriptionboolean
Says whether this instance of Request Listener is allowed to run -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
changeName
(String usr) Changes name if availablevoid
Handles the received messageread()
Reads from the socket's input streamvoid
run()
Thread.run() implementation.void
sendList()
Sends to the client a list of connected userstoString()
void
Sends 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
-