Class SocketTxRx

java.lang.Object
cbsw.SocketTxRx

public class SocketTxRx extends Object

A class that encapsulates a socket connection.

  • Field Details

  • Constructor Details

    • SocketTxRx

      public SocketTxRx()
  • Method Details

    • rx

      public String rx(int timeout)

      Reads a message from the rx channel.

      Parameters:
      timeout - Socket timeout in milliseconds. 0 for no timeout.
      Returns:
      The message string
    • tx

      public void tx(String message)

      Writes a message to the tx channel.

      Parameters:
      message - The message string
    • rxFlush

      public void rxFlush()

      Cleans out any pending messages.

      Reads socket until it times out indicating no more data.

    • makeServerSocket

      public void makeServerSocket(URL url)

      Creates a server socket channel.

      Parameters:
      url - A URL to pass the port number
    • makeSocket

      public void makeSocket(URL url)

      Creates a socket channel.

      Parameters:
      url - A URL to pass the internet address
    • accept

      public void accept()

      Accepts a server socket connection and creates tx/rx channels.

    • main

      public static void main(String[] args)

      An example program that replies ACK_OK to any message.

      Creates and listens on a server socket. When a connection is made, responds with ACK_OK to all messages.

      When the connection is broken, waits for a new connection.

      Parameters:
      args - Command-line parameters