Package it.meucci
Class Client
java.lang.Object
it.meucci.Client
Represents client. Has some methods to write/send message from/to the Socket's input and output streams.
-
Field Summary
Modifier and TypeFieldDescriptionThe UserMessagesList object used to handle messages and users -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Used to change user's username from the pending one.Gets the current username.void
Initializes the ReplyListener and starts it.void
Sends a message to the socket's ouput streamvoid
setPendingUsername
(String username) void
stop()
Stops the client's socket
-
Field Details
-
userMessagesList
The UserMessagesList object used to handle messages and users
-
-
Constructor Details
-
Client
The client costructor.- Parameters:
address
- The IP address of the ServerSocketport
- The port on which the ServerSocket listens to- Throws:
IOException
- When socket or DataOutputStream can't be created successfully.
-
-
Method Details
-
initListener
public void initListener()Initializes the ReplyListener and starts it. Must be called once and after the successful creation of the client. -
send
Sends a message to the socket's ouput stream- Parameters:
message
- The message to be serialized and sent
-
changeUsername
public void changeUsername()Used to change user's username from the pending one. -
stop
Stops the client's socket- Throws:
IOException
- inherited from socket.close() -- thrown when it's impossible to stop the client.
-
getSocket
-
getUsername
Gets the current username. If it's null, `""` is automatically returned.- Returns:
-
setPendingUsername
-