Package com.example.client.app
Class BaseClient
java.lang.Object
com.example.client.app.BaseClient
- All Implemented Interfaces:
Client
The BaseClient class implements the Client interface and represents a basic client working with a chat application.
-
Constructor Summary
ConstructorsConstructorDescriptionBaseClient
(int clientPort, MessageSender messageSender, StreamIO streamIO, Listener listener) Constructs a BaseClient with the specified client port, message sender, stream IO, and listener. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Logs in with the specified nickname and client port.void
Logs out and stops the client by sending an exit command and interrupting the listener.void
sendMessage
(String message) Sends a message to the server with the client's nickname and message content.void
start()
Starts the work of the client, including setting up the listener and reading user input.void
Launch the input message listener
-
Constructor Details
-
BaseClient
public BaseClient(int clientPort, MessageSender messageSender, StreamIO streamIO, Listener listener) Constructs a BaseClient with the specified client port, message sender, stream IO, and listener.- Parameters:
clientPort
- the port number of the clientmessageSender
- the message sender for sending messagesstreamIO
- the stream IO interface for input-output processinglistener
- the listener for input messages from the thread
-
-
Method Details
-
start
public void start()Starts the work of the client, including setting up the listener and reading user input. -
login
Logs in with the specified nickname and client port.- Specified by:
login
in interfaceClient
- Parameters:
nickname
- the nickname of the client- Returns:
- true if the login is successful, false otherwise
- Throws:
IOException
- if an error occurs during login
-
logoutAndStop
Logs out and stops the client by sending an exit command and interrupting the listener.- Specified by:
logoutAndStop
in interfaceClient
- Throws:
IOException
- if an error occurs during logout
-
sendMessage
Sends a message to the server with the client's nickname and message content.- Specified by:
sendMessage
in interfaceClient
- Parameters:
message
- the message content to send- Throws:
IOException
- if an error occurs during message sending
-
startListener
public void startListener()Launch the input message listener- Specified by:
startListener
in interfaceClient
-