Class TCPClient

java.lang.Object
com.ensea_chatapp_tcp.Client.TCPClient

public class TCPClient extends Object
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 Details

    • TCPClient

      public TCPClient()
    • TCPClient

      public TCPClient(String host)
    • TCPClient

      public TCPClient(String host, int port)
  • Method Details

    • main

      public static void main(String[] args) throws IOException
      Throws:
      IOException
    • launch

      public void launch() throws IOException
      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

      public void asynchronous_fetch(DataFetchHandler handler)
      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

      public String fetch_data() throws IOException
      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

      public void send_data(String dataStr) throws IOException
      send String data to Server
      Parameters:
      dataStr - The data which will be sent to Server
      Throws:
      IOException