java.lang.Object
java.net.Socket
net.i2p.util.InternalSocket
- All Implemented Interfaces:
Closeable, AutoCloseable
A simple in-JVM Socket using Piped Streams. We use port numbers just like regular sockets. Can only connect to InternalServerSocket.
Constructor Summary
ConstructorsConstructorDescriptionInternalSocket(int port) Client side.InternalSocket(InputStream is, OutputStream os) Server side.Method Summary
Modifier and TypeMethodDescriptionvoidclose()Close both streams.Input stream connected to the internal server.intSupported as of 0.9.33, prior to that threw UnsupportedOperationException.Output stream connected to the internal server.intgetPort()Supported as of 0.9.33, prior to that threw UnsupportedOperationException.static SocketConvenience method to return either a Socket or an InternalSocket.intSupported as of 0.9.33, prior to that threw UnsupportedOperationException.intAlways returns 0, even if setSoTimeout() was called.booleanisClosed()True if either stream is null.booleanSupported as of 0.9.33, prior to that threw UnsupportedOperationException.booleanSupported as of 0.9.33, prior to that threw UnsupportedOperationException.booleanSupported as of 0.9.33, prior to that threw UnsupportedOperationException.(package private) voidInput stream.(package private) voidOutput stream.voidsetSoLinger(boolean on, int linger) Does nothing as of 0.9.33, prior to that threw UnsupportedOperationException.voidsetSoTimeout(int timeout) Supported as of 0.9.34, if constructed with TimeoutPipedInputStream and TimeoutPipedOutputStream.voidSupported as of 0.9.33, prior to that threw UnsupportedOperationException.voidFlushes (as the Socket javadocs advise) and closes.toString()Descriptive label.Methods inherited from class Socket
bind, connect, connect, getChannel, getInetAddress, getKeepAlive, getLocalAddress, getLocalSocketAddress, getOOBInline, getOption, getReceiveBufferSize, getRemoteSocketAddress, getReuseAddress, getSendBufferSize, getTcpNoDelay, getTrafficClass, isBound, sendUrgentData, setKeepAlive, setOOBInline, setOption, setReceiveBufferSize, setReuseAddress, setSendBufferSize, setTcpNoDelay, setTrafficClass, supportedOptions
Constructor Details
InternalSocket
InternalSocket(InputStream is, OutputStream os) Server side.- Parameters:
is- the piped stream carrying data from the client to this endos- the piped stream carrying data from this end to the client
InternalSocket
Client side.- Parameters:
port- > 0- Throws:
IOException- if the port is not positive, or no internal server is listening on it
Method Details
getSocket
Convenience method to return either a Socket or an InternalSocket.- Parameters:
host- the host requested, which is only honoured for the loopback names inside a running routerport- > 0- Returns:
- an
InternalSocketwhen running under a router and the host is a loopback name, otherwise a TCPSocketto the host and port - Throws:
IOException- if neither an internal socket nor a TCP socket to the given host and port can be opened
getInputStream
Input stream connected to the internal server.- Overrides:
getInputStreamin classSocket- Returns:
- the input stream
getOutputStream
Output stream connected to the internal server.- Overrides:
getOutputStreamin classSocket- Returns:
- the output stream
setInputStream
Input stream.- Parameters:
is- the replacement stream, installed by the internal server after a client has connected
setOutputStream
Output stream.- Parameters:
os- the replacement stream, installed by the internal server after a client has connected
close
isClosed
toString
setSoTimeout
public void setSoTimeout(int timeout) Supported as of 0.9.34, if constructed with TimeoutPipedInputStream and TimeoutPipedOutputStream. Otherwise, does nothing.- Overrides:
setSoTimeoutin classSocket- See Also:
getSoTimeout
public int getSoTimeout()Always returns 0, even if setSoTimeout() was called.- Overrides:
getSoTimeoutin classSocket- Returns:
- the so timeout
getLocalPort
public int getLocalPort()Supported as of 0.9.33, prior to that threw UnsupportedOperationException.- Overrides:
getLocalPortin classSocket- Returns:
- 1 if connected, -1 if not
getPort
getSoLinger
public int getSoLinger()Supported as of 0.9.33, prior to that threw UnsupportedOperationException.- Overrides:
getSoLingerin classSocket- Returns:
- -1 always
isConnected
public boolean isConnected()Supported as of 0.9.33, prior to that threw UnsupportedOperationException.- Overrides:
isConnectedin classSocket- Returns:
- true unless both streams are shut down; a plain socket is never "connected"
isInputShutdown
public boolean isInputShutdown()Supported as of 0.9.33, prior to that threw UnsupportedOperationException.- Overrides:
isInputShutdownin classSocket- Returns:
- whether input shutdown
isOutputShutdown
public boolean isOutputShutdown()Supported as of 0.9.33, prior to that threw UnsupportedOperationException.- Overrides:
isOutputShutdownin classSocket- Returns:
- whether output shutdown
setSoLinger
public void setSoLinger(boolean on, int linger) Does nothing as of 0.9.33, prior to that threw UnsupportedOperationException.- Overrides:
setSoLingerin classSocket
shutdownInput
Supported as of 0.9.33, prior to that threw UnsupportedOperationException.- Overrides:
shutdownInputin classSocket- Throws:
IOException
shutdownOutput
Flushes (as the Socket javadocs advise) and closes. Supported as of 0.9.33, prior to that threw UnsupportedOperationException.- Overrides:
shutdownOutputin classSocket- Throws:
IOException