Package gda.io.socket

Class NativeSock

java.lang.Object
gda.io.socket.NativeSock
Direct Known Subclasses:
ODCCDNativeSock

public class NativeSock extends Object

Title: Socket wrapper with little to big endian conversion read methods.

Description: This class is a general purpose socket wrapper. It is particulary useful for reading from little endian byte streams (native Intel format). Some methods are provided to read java big endian data types from the little endian byte stream. Some methods are also provided to just read bytes or a line of bytes (eg. a ASCII string). The output stream is a Java buffered DataOutputStream.

  • Field Details

    • socket

      public Socket socket
      Socket reference.
    • outputStream

      protected DataOutputStream outputStream
      Output stream.
  • Constructor Details

    • NativeSock

      public NativeSock()
  • Method Details

    • connect

      public void connect(String host, int port) throws IOException, UnknownHostException, ConnectException
      Connect to the remote host
      Parameters:
      host - The remote hostname
      port -
      Throws:
      IOException
      UnknownHostException
      ConnectException
    • disconnect

      public void disconnect()
      Use this to disconnect from the remote host. It closes the socket and the input/output streams.
    • write

      public void write(String s) throws IOException
      Write a string (it will be terinputStreamated with a carriage return and end-of-line). This will only work with ASCII characters.
      Parameters:
      s - The string to write.
      Throws:
      IOException
    • readLine

      public String readLine() throws IOException
      Read a line of text. This assumes the text is in ASCII format. The method returns the result if a carriage return \n is reached.
      Returns:
      The resulting string.
      Throws:
      IOException
    • readByte

      public byte readByte() throws IOException
      Throws:
      IOException
    • readUntil

      public String readUntil(String pattern) throws IOException
      This reads the input stream byte-by-byte searching for a pattern. This only works with ASCII characters (8 bits).
      Parameters:
      pattern - The pattern to read until.
      Returns:
      The input stream in string format upto the end of the pattern.
      Throws:
      IOException
    • setSocketTimeOut

      public void setSocketTimeOut(int timeout)
      Use this to set the socket timeout
      Parameters:
      timeout -
    • getSocketTimeOut

      public int getSocketTimeOut()
      Use this to read the socket timeout
      Returns:
      int