Package com.ensea_chatapp_tcp.Client
Class TCPClient
java.lang.Object
com.ensea_chatapp_tcp.Client.TCPClient
This is a class to implement a TCP Client needed to connect to the chat TCP server
The class takes two optional command line arguments: the first argument is the server ip address, and the second argument is server ip address. In the case that the address or ports are absent, the localhost is the default address and 8439 is the default port.
Usage: java com.ensea_chatapp_tcp.Client.TCPClient
Usage: java com.ensea_chatapp_tcp.Client.TCPClient server_ip
Usage: java com.ensea_chatapp_tcp.Client.TCPClient server_ip server_port
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidasynchronous_fetch(DataFetchHandler handler) Start a thread in order to fetch the data from server asynchronously.Try to fetch datavoidlaunch()static voidvoidsend String data to Servervoidsend data read from console to server and fetch the data available from server synchronously The function will continue fetch sending/fetching cycle infinitely
-
Constructor Details
-
TCPClient
public TCPClient() -
TCPClient
-
TCPClient
-
-
Method Details
-
main
- Throws:
IOException
-
launch
- Throws:
IOException
-
synchronous_send_and_fetch
public void synchronous_send_and_fetch()send data read from console to server and fetch the data available from server synchronously The function will continue fetch sending/fetching cycle infinitely -
asynchronous_fetch
Start a thread in order to fetch the data from server asynchronously. The thread will continue fetch infinitely- Parameters:
handler- The handler invoked when a data is available. The handler must take 1 argument as fetched data
-
fetch_data
Try to fetch data- Returns:
- if there is data available, it will return it as String, otherwise it will return null
- Throws:
IOException
-
send_data
send String data to Server- Parameters:
dataStr- The data which will be sent to Server- Throws:
IOException
-