Class TSocket

All Implemented Interfaces:
Closeable, AutoCloseable

public class TSocket extends TIOStreamTransport
Socket implementation of the TTransport interface. To be commented soon!
  • Constructor Details

    • TSocket

      public TSocket(Socket socket) throws TTransportException
      Constructor that takes an already created socket.
      Parameters:
      socket - Already created socket object
      Throws:
      TTransportException - if there is an error setting up the streams
    • TSocket

      public TSocket(TConfiguration config, String host, int port) throws TTransportException
      Creates a new unconnected socket that will connect to the given host on the given port.
      Parameters:
      config - check config
      host - Remote host
      port - Remote port
      Throws:
      TTransportException
    • TSocket

      public TSocket(String host, int port) throws TTransportException
      Creates a new unconnected socket that will connect to the given host on the given port.
      Parameters:
      host - Remote host
      port - Remote port
      Throws:
      TTransportException
    • TSocket

      public TSocket(String host, int port, int timeout) throws TTransportException
      Creates a new unconnected socket that will connect to the given host on the given port.
      Parameters:
      host - Remote host
      port - Remote port
      timeout - Socket timeout and connection timeout
      Throws:
      TTransportException
    • TSocket

      public TSocket(TConfiguration config, String host, int port, int timeout) throws TTransportException
      Creates a new unconnected socket that will connect to the given host on the given port.
      Parameters:
      config - check config
      host - Remote host
      port - Remote port
      timeout - Socket timeout and connection timeout
      Throws:
      TTransportException
    • TSocket

      public TSocket(TConfiguration config, String host, int port, int socketTimeout, int connectTimeout) throws TTransportException
      Creates a new unconnected socket that will connect to the given host on the given port, with a specific connection timeout and a specific socket timeout.
      Parameters:
      config - check config
      host - Remote host
      port - Remote port
      socketTimeout - Socket timeout
      connectTimeout - Connection timeout
      Throws:
      TTransportException
  • Method Details

    • setTimeout

      public void setTimeout(int timeout)
      Sets the socket timeout and connection timeout.
      Parameters:
      timeout - Milliseconds timeout
    • setConnectTimeout

      public void setConnectTimeout(int timeout)
      Sets the time after which the connection attempt will time out
      Parameters:
      timeout - Milliseconds timeout
    • setSocketTimeout

      public void setSocketTimeout(int timeout)
      Sets the socket timeout
      Parameters:
      timeout - Milliseconds timeout
    • getSocket

      public Socket getSocket()
      Returns a reference to the underlying socket.
    • isOpen

      public boolean isOpen()
      Checks whether the socket is connected.
      Overrides:
      isOpen in class TIOStreamTransport
      Returns:
      false after close is called.
    • open

      public void open() throws TTransportException
      Connects the socket, creating a new socket object if necessary.
      Overrides:
      open in class TIOStreamTransport
      Throws:
      TTransportException - if the transport could not be opened
    • close

      public void close()
      Closes the socket.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class TIOStreamTransport