host.com
system at port 79
. Note that RFC1900 recommends the use of names rather than IP numbers for best results in the event of IP number reassignment.
Every StreamConnection
provides a Connection
object as well as an InputStream
and OutputStream
to handle the I/O associated with the connection. Each of these interfaces has its own close()
method. For systems that support duplex communication over the socket connection, closing of the input or output stream SHOULD shutdown just that side of the connection. e.g. closing the InputStream
will permit the OutputStream
to continue sending data.
Once the input or output stream has been closed, it can only be reopened with a call to Connector.open()
. The application will receive an IOException
if an attempt is made to reopen the stream.
The URI must conform to the BNF syntax specified below. If the URI does not conform to this syntax, an IllegalArgumentException
is thrown.
<socket_connection_string> | ::= "socket://"<hostport> |
<hostport> | ::= host ":" port |
<host> | ::= host name or IP address (omitted for inbound connections, See ServerSocketConnection) |
<port> | ::= numeric port number |
The following examples show how a SocketConnection
would be used to access a sample loopback program.
SocketConnection sc = (SocketConnection) Connector.open("socket://host.com:79"); sc.setSocketOption(SocketConnection.LINGER, 5); InputStream is = sc.openInputStream(); OutputStream os = sc.openOutputStream(); os.write("\r\n".getBytes()); int ch = 0; while(ch != -1) { ch = is.read(); } is.close(); os.close(); sc.close();
SocketConnection
is used to manage connections from a server socket. In order to achieve this it spawns a task to listen for incoming connect requests. When a TCP connection request arrives it hands off the SocketChannel
to the Server
which processes the request. This handles connections from a ServerSocketChannel
object so that features such as SSL can be used by a server that uses this package. The background acceptor process will terminate if the connection is closed.
@author Niall Gallagher
@see org.simpleframework.transport.Server
|
|