public class SocketConnectionFacadeImpl extends Object implements SocketConnectionFacade
Modifier and Type | Field and Description |
---|---|
static Pattern |
CRNL_PATTERN |
static int |
MAX_SOCKET_READ_TIMEOUT_MILLIS
3 hrs = 3 * 3660 * 1000
|
static Pattern |
NL_PATTERN |
Constructor and Description |
---|
SocketConnectionFacadeImpl(String host,
int port,
boolean ssl,
int timeout,
int readTimeout)
<<<<<<< HEAD Creates a new instance for use with the Manager API that
uses UTF-8 as encoding and CRNL ("\r\n") as line delimiter.
|
SocketConnectionFacadeImpl(String host,
int port,
boolean ssl,
int timeout,
int readTimeout,
Charset encoding)
Creates a new instance for use with the Manager API that uses the given
encoding and CRNL ("\r\n") as line delimiter.
|
SocketConnectionFacadeImpl(String host,
int port,
boolean ssl,
int timeout,
int readTimeout,
Charset encoding,
Pattern lineDelimiter)
Creates a new instance for use with the Manager API that uses the given
encoding and line delimiter.
|
SocketConnectionFacadeImpl(String host,
int port,
boolean ssl,
int timeout,
int readTimeout,
Pattern lineDelimiter)
Creates a new instance for use with the Manager API that uses UTF-8 as
encoding and the given line delimiter.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes the socket connection including its input and output stream and
frees all associated ressources.
|
void |
flush()
Flushes the socket connection by sending any buffered but yet unsent
data.
|
InetAddress |
getLocalAddress()
Returns the local address this socket connection.
|
int |
getLocalPort()
Returns the local port of this socket connection.
|
InetAddress |
getRemoteAddress()
Returns the remote address of this socket connection.
|
int |
getRemotePort()
Returns the remote port of this socket connection.
|
boolean |
isConnected()
Returns the connection state of the socket.
|
String |
readLine()
Reads a line of text from the socket connection.
|
void |
write(String s)
Sends a given String to the socket connection.
|
public static final Pattern CRNL_PATTERN
public static final Pattern NL_PATTERN
public static final int MAX_SOCKET_READ_TIMEOUT_MILLIS
public SocketConnectionFacadeImpl(String host, int port, boolean ssl, int timeout, int readTimeout) throws IOException
host
- the foreign host to connect to.port
- the foreign port to connect to.ssl
- true
to use SSL, false
otherwise.timeout
- 0 incidcates defaultreadTimeout
- see Socket.setSoTimeout(int)
IOException
- if the connection cannot be established.public SocketConnectionFacadeImpl(String host, int port, boolean ssl, int timeout, int readTimeout, Charset encoding) throws IOException
host
- the foreign host to connect to.port
- the foreign port to connect to.ssl
- true
to use SSL, false
otherwise.timeout
- 0 incidcates defaultreadTimeout
- see Socket.setSoTimeout(int)
encoding
- the encoding used for transmission of strings (all
connections should use the same encoding)IOException
- if the connection cannot be established.public SocketConnectionFacadeImpl(String host, int port, boolean ssl, int timeout, int readTimeout, Pattern lineDelimiter) throws IOException
host
- the foreign host to connect to.port
- the foreign port to connect to.ssl
- true
to use SSL, false
otherwise.timeout
- 0 incidcates defaultreadTimeout
- see Socket.setSoTimeout(int)
lineDelimiter
- a Pattern
for matching the line delimiter
for the socketIOException
- if the connection cannot be established.public SocketConnectionFacadeImpl(String host, int port, boolean ssl, int timeout, int readTimeout, Charset encoding, Pattern lineDelimiter) throws IOException
host
- the foreign host to connect to.port
- the foreign port to connect to.ssl
- true
to use SSL, false
otherwise.timeout
- 0 incidcates defaultreadTimeout
- see Socket.setSoTimeout(int)
encoding
- the encoding used for transmission of strings (all
connections should use the same encoding)lineDelimiter
- a Pattern
for matching the line delimiter
for the socketIOException
- if the connection cannot be established.public String readLine() throws IOException
SocketConnectionFacade
Depending on the implementation different newline delimiters are used ("\r\n" for the Manager API and "\n" for AGI).
readLine
in interface SocketConnectionFacade
IOException
- if the connection has been closed.public void write(String s) throws IOException
SocketConnectionFacade
write
in interface SocketConnectionFacade
s
- the String to send.IOException
- if the String cannot be sent, maybe because the
connection has already been closed.public void flush() throws IOException
SocketConnectionFacade
flush
in interface SocketConnectionFacade
IOException
- if the connection cannot be flushed.public void close() throws IOException
SocketConnectionFacade
When calling close() any Thread currently blocked by a call to readLine() will be unblocked and receive an IOException.
close
in interface SocketConnectionFacade
IOException
- if the socket connection cannot be closed.public boolean isConnected()
SocketConnectionFacade
isConnected
in interface SocketConnectionFacade
true
if the socket successfuly connected to a
serverpublic InetAddress getLocalAddress()
SocketConnectionFacade
getLocalAddress
in interface SocketConnectionFacade
public int getLocalPort()
SocketConnectionFacade
getLocalPort
in interface SocketConnectionFacade
public InetAddress getRemoteAddress()
SocketConnectionFacade
getRemoteAddress
in interface SocketConnectionFacade
public int getRemotePort()
SocketConnectionFacade
getRemotePort
in interface SocketConnectionFacade
Copyright © 2004–2021. All rights reserved.