|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.indy.io.AbstractIOHandler | +--org.indy.io.IOHandlerSocket
An implementation of IOHandler
that handles IO for sockets.
IOHandler
,
AbstractIOHandler
Field Summary | |
protected java.net.Socket |
binding
Instance of java.net.Socket used by this IOHandler. |
protected static int |
CR
Carriage Return |
protected static int |
LF
Line Feed |
Fields inherited from class org.indy.io.AbstractIOHandler |
listenerList, maximumLineLength, readTimeOut |
Constructor Summary | |
IOHandlerSocket()
Constructs a new instance of IOHandlerSocket |
|
IOHandlerSocket(java.net.Socket socket)
Constructs a new instance of IOHandlerSocket
around a pre-made java.net.Socket |
Method Summary | |
int |
available()
Returns the number of bytes that be read from the socket and buffer without blocking |
void |
clearBuffer()
Clears the internal buffer used by this socket |
void |
close()
Closes this socket connection. |
void |
connectClient(java.util.Map parameters,
int timeout)
Connects to a remote socket using the parameters given in map. |
void |
connectClient(java.lang.String host,
int port,
java.lang.String boundIP,
int boundPort,
int timeout)
Connects this IOHandlerSocket to a remote socket whose address is given by
host as either an IP address or FQDN and whose port is given by port
If boundIP or boundPort are not null or < 1 respectively, the socket will bind
to this local address and / or port. |
byte[] |
currentReadBuffer()
Returns the current data that can be read from the socket without blocking |
void |
flush()
Flushes the output buffer of this IOHandlerSocket |
java.lang.String |
getBoundIP()
Gets a string representation of the local IP address that this socket is bound to, or throws an exception if the socket is not bound. |
int |
getBoundPort()
Gets the local port number that this socket is bound to. |
java.lang.String |
getPeerIP()
Returns a string representing the IP address of the peer that this socket is connected to, or a blank string if the socket is not connected. |
int |
getPeerPort()
Gets the remote port to which this socket is connected, or 0 if unconnected |
int |
getReadTimeOut()
DOCUMENT ME! |
protected SocksInfo |
getSocksInfo()
Gets the SOCKS data in use with this IOHandlerSocket |
boolean |
getUseNagle()
Returns whether this socket is using Nagle's Algortihm. |
boolean |
isConnected()
Returns whether or not this instance is connected. |
int |
read()
Reads a single byte of data from the socket |
int |
read(byte[] b,
int off,
int len,
int timeout)
Reads a sequence of bytes from the socket, using the specified timeout. |
int |
read(int timeout)
DOCUMENT ME! |
java.lang.String |
readLine(int timeout,
int maxLineLength,
java.lang.String encoding)
Reads a line of data from the socket and assembles it using the given encoding. |
void |
setReadTimeOut(int newReadTimeOut)
DOCUMENT ME! |
protected void |
setSocksInfo(SocksInfo info)
Sets the SOCKS configuration to be used with this socket connection. |
void |
setUseNagle(boolean use)
Sets whether to use Nagle's Algorithm with this socket or not. |
void |
write(byte[] b)
Writes a sequence of bytes to the socket |
void |
write(byte[] b,
int off,
int len)
Writes a seqeunce of bytes to the socket |
void |
write(int b)
Writes a single byte to the socket |
Methods inherited from class org.indy.io.AbstractIOHandler |
addIOHandlerListener, afterAccept, doOnConnect, doOnDisconnect, doStatus, getMaximumLineLength, open, read, read, read, readLine, readLine, removeIOHandlerListener, setMaximumLineLength |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected static final int CR
protected static final int LF
protected java.net.Socket binding
java.net.Socket
used by this IOHandler.Constructor Detail |
public IOHandlerSocket(java.net.Socket socket) throws IndyIOException
IOHandlerSocket
around a pre-made java.net.Socket
socket
- The socket to use with the IOHandlerIndyIOException
- If an IO error occurs whilst configuring the socketpublic IOHandlerSocket()
IOHandlerSocket
Method Detail |
protected void setSocksInfo(SocksInfo info)
info
- The new socks configuration data to be used.public void setUseNagle(boolean use) throws IndyIOException
true
use
- true
to use Nagle's Algorithm, false
otherwiseIndyIOException
- if the underlying socket throws an exception whilst setting this propertySocket.setTcpNoDelay(boolean)
protected SocksInfo getSocksInfo()
IOHandlerSocket
public java.lang.String getPeerIP()
public int getPeerPort()
public java.lang.String getBoundIP() throws IndyException
IndyException
- If the socket is not boundconnectClient
public int getBoundPort() throws IndyException
IndyException
- if the socket is not boundconnectClient
public boolean getUseNagle() throws IndyIOException
true
if the socket is using Nagle's Algorithm, false
otherwisepublic boolean isConnected()
true
if the socket is connected.public void flush() throws IndyIOException
IOHandlerSocket
IndyIOException
- If an IO error occurs whilst flushingNotConnectedException
- if the socket is not connectedpublic void write(byte[] b, int off, int len) throws IndyIOException
b
- An array of bytes containing the dataoff
- The offset at which to start writinglen
- The number of bytes to writeIndyIOException
- If an IO error occursNotConnectedException
- if the socket is not connectedjava.lang.IndexOutOfBoundsException
- if there are illegal values of b,off,or len
public void write(byte[] b) throws IndyIOException
b
- The data to writeIndyIOException
- If an IO error occurswrite(byte[],int,int)
public void write(int b) throws IndyIOException
b
- The byte to writeIndyIOException
- If an IO error occurspublic int read() throws IndyIOException, PeerDisconnectedException, ReadTimedOutException
IndyIOException
- if an IO error occurs.PeerDisconnectedException
- if the remote machine has disconnectedReadTimedOutException
- if the read opertaion timed outNotConnectedException
- if the socket is not connectedpublic int read(int timeout) throws IndyIOException
timeout
- DOCUMENT ME!IndyIOException
- DOCUMENT ME!public int read(byte[] b, int off, int len, int timeout) throws IndyIOException, ReadTimedOutException
b
- An array of bytes to read the data intooff
- The offset at which to start writing to b
len
- The amount of data to readtimeout
- The timeout to use for readingIndyIOException
- If an IO error occurs.PeerDisconnectedException
- if the remote machine has disconnectedReadTimedOutException
- if the read opertaion timed outNotConnectedException
- if the socket is not connectedjava.lang.IndexOutOfBoundsException
- if b,off, or len are illegalNullPointerException
- if b is nullAbstractIOHandler.read(byte[],int,int)
,
AbstractIOHandler.read(byte[],int)
,
AbstractIOHandler.read(byte[])
,
read()
public int available() throws IndyIOException
IndyIOException
- if an IO error occurspublic void connectClient(java.util.Map parameters, int timeout) throws IndyIOException
Key | Value | Type | Required |
---|---|---|---|
"host" | The IP address or FQDN of the remote host to connect to | java.lang.String | Yes |
"port" | The port of the remote host to connect to | java.lang.Stringr | Yes |
"boundip" | The local IP address to bind to | java.lang.String | No |
"boundport" | The local port to bind to | java.lang.String | No |
connectClient
in class AbstractIOHandler
parameters
- The parameters to use for connection (see above)timeout
- The timeout to use for this connection attemptIndyIOException
- if an IO error occurs.java.lang.IllegalArgumentException
- if parameters
does not contain a required entry (see above)public void connectClient(java.lang.String host, int port, java.lang.String boundIP, int boundPort, int timeout) throws IndyIOException, ConnectException, ConnectTimedOutException, IndyUnknownHostException
IOHandlerSocket
to a remote socket whose address is given by
host
as either an IP address or FQDN and whose port is given by port
If boundIP
or boundPort
are not null
or < 1 respectively, the socket will bind
to this local address and / or port.host
- The remote host to connect to.port
- The remote port to connect to.boundIP
- The local address to bind toboundPort
- The local port to bind to.timeout
- The timeout to use for this connection attemptIndyIOException
- If an IO error occurs.ConnectException
- If a connection error occurs, such as the connection being refused by the remote hostConnectTimedOutException
- If the connection attempt times outIndyUnknownHostException
- If the host can not be resolved.public void close()
close
in class AbstractIOHandler
org.indy.io.AbstractIOHandler
IOHandler.close()
public void clearBuffer()
public java.lang.String readLine(int timeout, int maxLineLength, java.lang.String encoding) throws IndyIOException, PeerDisconnectedException, ReadTimedOutException, MaxLineLengthExceededException
null
the default platform encoding is used.timeout
- The timeout to use for this operationmaxLineLength
- The maxiumum line length to acceptencoding
- The character encoding to use to assmble the stringIndyIOException
- if an IO error occursPeerDisconnectedException
- if the remote machine disconnects normallyReadTimedOutException
- if the operation times outMaxLineLengthExceededException
- if the maximum line length is exceeded before a line break is foundAbstractIOHandler.readLine(int,int)
public byte[] currentReadBuffer() throws IndyIOException
IndyIOException
- If an IO error occurs.public void setReadTimeOut(int newReadTimeOut) throws IndyIOException
setReadTimeOut
in class AbstractIOHandler
newReadTimeOut
- DOCUMENT ME!IndyIOException
- DOCUMENT ME!public int getReadTimeOut() throws IndyIOException
getReadTimeOut
in class AbstractIOHandler
IndyIOException
- DOCUMENT ME!
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |