net.i2p.util

## Class InternalSocket

- java.lang.Object
- - java.net.Socket
  - - net.i2p.util.InternalSocket

- All Implemented Interfaces:
    Closeable, AutoCloseable

      public class InternalSocket
      extends Socket

  A simple in-JVM Socket using Piped Streams. We use port numbers just like regular sockets. Can only connect to InternalServerSocket.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `InternalSocket(InputStream is, OutputStream os)` server side
    `InternalSocket(int port)` client side

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `close()`
    `InputStream` | `getInputStream()`
    `int` | `getLocalPort()` Supported as of 0.9.33, prior to that threw UnsupportedOperationException
    `OutputStream` | `getOutputStream()`
    `int` | `getPort()` Supported as of 0.9.33, prior to that threw UnsupportedOperationException
    `static Socket` | `getSocket(String host, int port)` Convenience method to return either a Socket or an InternalSocket
    `int` | `getSoLinger()` Supported as of 0.9.33, prior to that threw UnsupportedOperationException
    `int` | `getSoTimeout()` Always returns 0, even if setSoTimeout() was called.
    `boolean` | `isClosed()`
    `boolean` | `isConnected()` Supported as of 0.9.33, prior to that threw UnsupportedOperationException
    `boolean` | `isInputShutdown()` Supported as of 0.9.33, prior to that threw UnsupportedOperationException
    `boolean` | `isOutputShutdown()` Supported as of 0.9.33, prior to that threw UnsupportedOperationException
    `(package private) void` | `setInputStream(InputStream is)`
    `(package private) void` | `setOutputStream(OutputStream os)`
    `void` | `setSoLinger(boolean on, int linger)` Does nothing as of 0.9.33, prior to that threw UnsupportedOperationException
    `void` | `setSoTimeout(int timeout)` Supported as of 0.9.34, if constructed with TimeoutPipedInputStream and TimeoutPipedOutputStream.
    `void` | `shutdownInput()` Supported as of 0.9.33, prior to that threw UnsupportedOperationException
    `void` | `shutdownOutput()` Flushes (as the Socket javadocs advise) and closes.
    `String` | `toString()`

    - ### Methods inherited from class java.net.Socket

      `bind, connect, connect, getChannel, getInetAddress, getKeepAlive, getLocalAddress, getLocalSocketAddress, getOOBInline, getReceiveBufferSize, getRemoteSocketAddress, getReuseAddress, getSendBufferSize, getTcpNoDelay, getTrafficClass, isBound, sendUrgentData, setKeepAlive, setOOBInline, setPerformancePreferences, setReceiveBufferSize, setReuseAddress, setSendBufferSize, setSocketImplFactory, setTcpNoDelay, setTrafficClass`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### InternalSocket

          InternalSocket(InputStream is,
                         OutputStream os)

      server side

    - #### InternalSocket

          public InternalSocket(int port)
                         throws IOException

      client side
      Parameters:
        `port` - > 0
      Throws:
        `IOException`

  - ### Method Detail

    - #### close

          public void close()

      Specified by:
        `close` in interface `Closeable`
      Specified by:
        `close` in interface `AutoCloseable`
      Overrides:
        `close` in class `Socket`

    - #### getInputStream

          public InputStream getInputStream()

      Overrides:
        `getInputStream` in class `Socket`

    - #### getLocalPort

          public int getLocalPort()

      Supported as of 0.9.33, prior to that threw UnsupportedOperationException
      Overrides:
        `getLocalPort` in class `Socket`
      Returns:
        1 if connected, -1 if not

    - #### getOutputStream

          public OutputStream getOutputStream()

      Overrides:
        `getOutputStream` in class `Socket`

    - #### getPort

          public int getPort()

      Supported as of 0.9.33, prior to that threw UnsupportedOperationException
      Overrides:
        `getPort` in class `Socket`
      Returns:
        if connected: actual port for clients, 1 for servers; -1 if not

    - #### getSocket

          public static Socket getSocket(String host,
                                         int port)
                                  throws IOException

      Convenience method to return either a Socket or an InternalSocket
      Parameters:
        `port` - > 0
      Throws:
        `IOException`

    - #### getSoLinger

          public int getSoLinger()

      Supported as of 0.9.33, prior to that threw UnsupportedOperationException
      Overrides:
        `getSoLinger` in class `Socket`
      Returns:
        -1 always

    - #### getSoTimeout

          public int getSoTimeout()

      Always returns 0, even if setSoTimeout() was called.
      Overrides:
        `getSoTimeout` in class `Socket`

    - #### isClosed

          public boolean isClosed()

      Overrides:
        `isClosed` in class `Socket`

    - #### isConnected

          public boolean isConnected()

      Supported as of 0.9.33, prior to that threw UnsupportedOperationException
      Overrides:
        `isConnected` in class `Socket`

    - #### isInputShutdown

          public boolean isInputShutdown()

      Supported as of 0.9.33, prior to that threw UnsupportedOperationException
      Overrides:
        `isInputShutdown` in class `Socket`

    - #### isOutputShutdown

          public boolean isOutputShutdown()

      Supported as of 0.9.33, prior to that threw UnsupportedOperationException
      Overrides:
        `isOutputShutdown` in class `Socket`

    - #### setInputStream

          void setInputStream(InputStream is)

    - #### setOutputStream

          void setOutputStream(OutputStream os)

    - #### setSoLinger

          public void setSoLinger(boolean on,
                                  int linger)

      Does nothing as of 0.9.33, prior to that threw UnsupportedOperationException
      Overrides:
        `setSoLinger` in class `Socket`

    - #### setSoTimeout

          public void setSoTimeout(int timeout)

      Supported as of 0.9.34, if constructed with TimeoutPipedInputStream and TimeoutPipedOutputStream. Otherwise, does nothing.
      Overrides:
        `setSoTimeout` in class `Socket`
      See Also:
        `TimeoutPipedInputStream`

    - #### shutdownInput

          public void shutdownInput()
                             throws IOException

      Supported as of 0.9.33, prior to that threw UnsupportedOperationException
      Overrides:
        `shutdownInput` in class `Socket`
      Throws:
        `IOException`

    - #### shutdownOutput

          public void shutdownOutput()
                              throws IOException

      Flushes (as the Socket javadocs advise) and closes. Supported as of 0.9.33, prior to that threw UnsupportedOperationException
      Overrides:
        `shutdownOutput` in class `Socket`
      Throws:
        `IOException`

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Socket`