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
FieldsModifier and TypeFieldDescriptionThe UserMessagesList object used to handle messages and users -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidUsed to change user's username from the pending one.Gets the current username.voidInitializes the ReplyListener and starts it.voidSends a message to the socket's ouput streamvoidsetPendingUsername(String username) voidstop()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
-