public class SocketConnection extends Object implements SocketConnectionIf, MessageConnection
| Constructor and Description |
|---|
SocketConnection(Socket socket)
Constructs a TCP socket client connection from a given socket.
|
SocketConnection(String addr,
int port)
Constructs a TCP socket client connection from the given address and
port.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Terminates this object connection.
|
void |
connect(Map env)
Establish the connection.
|
String |
getConnectionId()
The ID for this connection.
|
Socket |
getSocket()
Returns a reference to the underlying socket.
|
Message |
readMessage()
Reads a
Message object from the other end of the
connection. |
void |
replaceStreams(InputStream is,
OutputStream os)
Replaces the current socket's input/output
streams by the ones provided.
|
void |
setSocket(Socket s)
Replaces the underlying socket.
|
void |
setSubject(Subject subject)
Sets the subject authenticated through this socket connection.
|
void |
writeMessage(Message msg)
Writes a
Message object to the other end of the
connection. |
public SocketConnection(Socket socket) throws IOException
socket - a TCP socket created by a user.IOExceptionpublic SocketConnection(String addr, int port) throws IOException
addr - the server host address.port - the server port.IOExceptionpublic void connect(Map env) throws IOException
MessageConnectionEstablish the connection. This method must be called before any other method of this interface. The behavior is unspecified if not.
connect in interface MessageConnectionenv - the properties of the connection.IOException - if the connection cannot be made.public Socket getSocket()
getSocket in interface SocketConnectionIfpublic void setSocket(Socket s) throws IOException
setSocket in interface SocketConnectionIfIOExceptionpublic void replaceStreams(InputStream is, OutputStream os) throws IOException
replaceStreams in interface SocketConnectionIfIOExceptionpublic void setSubject(Subject subject)
setSubject in interface SocketConnectionIfpublic Message readMessage() throws IOException, ClassNotFoundException
MessageConnectionReads a Message object from the other end of the
connection.
readMessage in interface MessageConnectionIOException - if a message could not be read because
of a communication problem.ClassNotFoundException - If the class of a serialized
object cannot be found.public void writeMessage(Message msg) throws IOException
MessageConnectionWrites a Message object to the other end of the
connection.
writeMessage in interface MessageConnectionmsg - the message to be written.IOException - if the message could not be written
because of a communication problem.public void close()
MessageConnectionTerminates this object connection. After calling this
method, any current or new call to readMessage or MessageConnection.writeMessage(Message) should produce an
IOException.
close in interface MessageConnectionpublic String getConnectionId()
MessageConnectionThe ID for this connection.
getConnectionId in interface MessageConnectionCopyright © 2019 Terracotta, Inc.. All rights reserved.