java.lang.Object
java.net.Socket
net.i2p.client.streaming.impl.StandardSocket
All Implemented Interfaces:
Closeable, AutoCloseable

public class StandardSocketextends Socket
Bridge to I2PSocket.

This extends Socket to make porting apps easier. Methods throw IOExceptions like Sockets do, rather than returning null for some methods.

StandardSockets are always bound, and always start out connected (unless connectDelay is > 0). You may not create an unbound StandardSocket. Create this through the SocketManager.

  • Field Details

    • _socket

      private final I2PSocket _socket
      The streaming socket being wrapped.
    • _connected

      private volatile boolean _connected
      False once the connection is lost.
    • _inputShutdown

      private volatile boolean _inputShutdown
      True once reading has stopped.
    • _outputShutdown

      private volatile boolean _outputShutdown
      True once writing has stopped.
    • _closed

      private volatile boolean _closed
      True once the socket is closed.
  • Constructor Details

    • StandardSocket

      StandardSocket(I2PSocket socket)
      Wraps an I2PSocket in a java.net.Socket.
      Parameters:
      socket - the I2PSocket that all traffic is delegated to
  • Method Details

    • bind

      public void bind(SocketAddress bindpoint)
      Binding is not supported.
      Overrides:
      bind in class Socket
      Throws:
      UnsupportedOperationException - always; the I2PSocket is supplied at construction, so there is nothing to bind
    • close

      public void close() throws IOException
      Closes the socket and the underlying I2PSocket.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class Socket
      Throws:
      IOException
    • connect

      public void connect(SocketAddress endpoint)
      Connecting is not supported.
      Overrides:
      connect in class Socket
      Throws:
      UnsupportedOperationException - always; the I2PSocket is supplied at construction, so there is nothing to connect
    • connect

      public void connect(SocketAddress endpoint, int timeout)
      Connecting is not supported.
      Overrides:
      connect in class Socket
      Throws:
      UnsupportedOperationException - always; the I2PSocket is supplied at construction, so there is nothing to connect
    • getChannel

      public SocketChannel getChannel()
      Channel is not supported.
      Overrides:
      getChannel in class Socket
      Returns:
      null always, unimplemented
    • getInetAddress

      public InetAddress getInetAddress()
      No remote address.
      Overrides:
      getInetAddress in class Socket
      Returns:
      null always
    • getInputStream

      public InputStream getInputStream() throws IOException
      Input stream from the underlying I2PSocket.
      Overrides:
      getInputStream in class Socket
      Returns:
      the input stream
      Throws:
      IOException - if the socket has no input stream
    • getKeepAlive

      public boolean getKeepAlive()
      Keep-alive setting.
      Overrides:
      getKeepAlive in class Socket
      Returns:
      true if keep-alive is enabled (inactivity action is SEND)
    • getLocalAddress

      public InetAddress getLocalAddress()
      No local address.
      Overrides:
      getLocalAddress in class Socket
      Returns:
      null always
    • getLocalPort

      public int getLocalPort()
      Local port.
      Overrides:
      getLocalPort in class Socket
      Returns:
      the port or 0 if unknown
    • getLocalSocketAddress

      public SocketAddress getLocalSocketAddress()
      Local socket address.
      Overrides:
      getLocalSocketAddress in class Socket
      Returns:
      an I2PSocketAddress, never null
    • getOOBInline

      public boolean getOOBInline()
      OOB inline is not supported.
      Overrides:
      getOOBInline in class Socket
      Returns:
      false always
    • getOutputStream

      public OutputStream getOutputStream() throws IOException
      Output stream from the underlying I2PSocket.
      Overrides:
      getOutputStream in class Socket
      Returns:
      the output stream
      Throws:
      IOException - if the socket has no output stream
    • getPort

      public int getPort()
      Remote port.
      Overrides:
      getPort in class Socket
      Returns:
      the port or 0 if unknown
    • getReceiveBufferSize

      public int getReceiveBufferSize()
      Inbound buffer size.
      Overrides:
      getReceiveBufferSize in class Socket
      Returns:
      the inbound buffer size, or 64KB if options are unavailable
    • getRemoteSocketAddress

      public SocketAddress getRemoteSocketAddress()
      Remote socket address.
      Overrides:
      getRemoteSocketAddress in class Socket
      Returns:
      an I2PSocketAddress, never null
    • getPeerDestination

      public Destination getPeerDestination()
      Returns the peer destination of the underlying I2PSocket.
      Returns:
      the peer destination, non-null
    • getReuseAddress

      public boolean getReuseAddress()
      Reuse address is not supported.
      Overrides:
      getReuseAddress in class Socket
      Returns:
      false always
    • getSendBufferSize

      public int getSendBufferSize()
      Buffer size.
      Overrides:
      getSendBufferSize in class Socket
      Returns:
      the buffer size, or 64KB if options are unavailable
    • getSoLinger

      public int getSoLinger()
      SO_LINGER is not implemented.
      Overrides:
      getSoLinger in class Socket
      Returns:
      -1 always (not implemented)
    • getSoTimeout

      public int getSoTimeout()
      Socket timeout.
      Overrides:
      getSoTimeout in class Socket
      Returns:
      the socket timeout in milliseconds
    • getTcpNoDelay

      public boolean getTcpNoDelay()
      TCP_NODELAY is not supported.
      Overrides:
      getTcpNoDelay in class Socket
      Returns:
      false always
    • getTrafficClass

      public int getTrafficClass()
      Traffic class is not supported.
      Overrides:
      getTrafficClass in class Socket
      Returns:
      0 always
    • isBound

      public boolean isBound()
      Always bound.
      Overrides:
      isBound in class Socket
      Returns:
      true always
    • isClosed

      public boolean isClosed()
      Whether closed.
      Overrides:
      isClosed in class Socket
      Returns:
      true once close() has run, false on a live wrapper
    • isConnected

      public boolean isConnected()
      Whether connected.
      Overrides:
      isConnected in class Socket
      Returns:
      true until close() has run, since the I2PSocket arrives connected
    • isInputShutdown

      public boolean isInputShutdown()
      Whether the input side has been shut down.
      Overrides:
      isInputShutdown in class Socket
      Returns:
      true if shutdownInput has been called
    • isOutputShutdown

      public boolean isOutputShutdown()
      Whether the output side has been shut down.
      Overrides:
      isOutputShutdown in class Socket
      Returns:
      true if shutdownOutput has been called
    • sendUrgentData

      public void sendUrgentData(int data)
      Urgent data is not supported.
      Overrides:
      sendUrgentData in class Socket
      Throws:
      UnsupportedOperationException - always; the underlying I2PSocket has no urgent-data channel
    • setKeepAlive

      public void setKeepAlive(boolean on)
      Keep-alive setting.
      Overrides:
      setKeepAlive in class Socket
      Parameters:
      on - true to enable keep-alive (inactivity action SEND), false for NOOP
    • setOOBInline

      public void setOOBInline(boolean on)
      OOB inline setting.
      Overrides:
      setOOBInline in class Socket
      Parameters:
      on - true to throw UnsupportedOperationException, false does nothing
      Throws:
      UnsupportedOperationException - if on is true
    • setPerformancePreferences

      public void setPerformancePreferences(int connectionTime, int latency, int bandwidth)
      Ignored, streaming sockets manage their own tuning.
    • setReceiveBufferSize

      public void setReceiveBufferSize(int size)
      Ignored, streaming sockets manage their own tuning.
      Overrides:
      setReceiveBufferSize in class Socket
    • setReuseAddress

      public void setReuseAddress(boolean on)
      Ignored, streaming sockets manage their own tuning.
      Overrides:
      setReuseAddress in class Socket
    • setSendBufferSize

      public void setSendBufferSize(int size)
      Ignored, streaming sockets manage their own tuning.
      Overrides:
      setSendBufferSize in class Socket
    • setSoLinger

      public void setSoLinger(boolean on, int linger)
      Ignored, streaming sockets manage their own tuning.
      Overrides:
      setSoLinger in class Socket
    • setSoTimeout

      public void setSoTimeout(int timeout) throws SocketException
      Socket timeout.
      Overrides:
      setSoTimeout in class Socket
      Parameters:
      timeout - the timeout in milliseconds
      Throws:
      SocketException - if the options are unavailable
    • setTcpNoDelay

      public void setTcpNoDelay(boolean on)
      Ignored, streaming sockets manage their own tuning.
      Overrides:
      setTcpNoDelay in class Socket
    • setTrafficClass

      public void setTrafficClass(int tc)
      Ignored, streaming sockets manage their own tuning.
      Overrides:
      setTrafficClass in class Socket
    • shutdownInput

      public void shutdownInput() throws IOException
      Shuts down the input side, closing the underlying I2PSocket.
      Overrides:
      shutdownInput in class Socket
      Throws:
      IOException
    • shutdownOutput

      public void shutdownOutput() throws IOException
      Shuts down the output side, closing the underlying I2PSocket.
      Overrides:
      shutdownOutput in class Socket
      Throws:
      IOException
    • toString

      public String toString()
      String representation of the underlying I2PSocket.
      Overrides:
      toString in class Socket