Package it.fi.meucci
Class Server
java.lang.Object
it.fi.meucci.Server
This class represents the server and contains some static methods used by other classes.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
accept()
Accepts incoming connections, giving them a dedicated thread.Cycles through the threads and checks if they have a valid username.boolean
isUserAvailable
(String username) Checks whether a username is available or not.boolean
isUserValid
(String username) Checks whether a username is valid or not.void
Used by other RequestListeners to send messages to one another.void
sendBroadcast
(Message msg) Used by other RequestListeners to send messages to everyone.
-
Constructor Details
-
Server
- Throws:
IOException
-
-
Method Details
-
accept
Accepts incoming connections, giving them a dedicated thread.- Throws:
IOException
-
getUsernames
Cycles through the threads and checks if they have a valid username.- Returns:
- a list of valid usernames the user can chat with
-
send
Used by other RequestListeners to send messages to one another. It sends it also to the sender.- Parameters:
msg
- The message to be sent
-
sendBroadcast
Used by other RequestListeners to send messages to everyone. It sends it also to the sender.- Parameters:
msg
- The message to be sent- Throws:
IOException
-
getListeners
- Returns:
- returns a list of listeners
-
isUserValid
Checks whether a username is valid or not.- Parameters:
username
- the username to be checked- Returns:
- true or false whether a username is valid or not.
-
isUserAvailable
Checks whether a username is available or not. Basically an ArrayList.contains() wrapper for better readability- Parameters:
username
- the username to be checked- Returns:
- true or false whether a username is available or not.
-