All Packages Class Hierarchy This Package Previous Next Index
Class AcmeNet.Assn2.Connection
AcmeNet.Assn2.Connection
- public class Connection
One end of a network connection.
Think of a connection as being like one end of a telephone call. It is paired with
another Connection object in another process somewhere. Anything put into this
Connection will pop out on the other end, and anything put into the other end will
pop out here.
A connection exposes two unidirectional I/O streams, one outbound to the other end,
and the other incoming. Each stream can carry an arbitrary stream of data.
-
csni
- The network interface used to send and receive packets on this connection.
-
inStream
- An input stream that can be given to applications that want to get data
that arrives on this connection.
-
MaxPacketLength
- The maximum packet size that can be sent without triggering an exception in
a lower-level network interface.
-
outStream
- An output stream that can be given to applications that want to send data
on this connection.
-
Connection()
- For use only by subclasses that override all methods.
-
Connection(NetAddress, ClientServerNI)
- Create a connection.
-
()
- Set up a daemon thread to watch for broken connections.
-
connect(ServiceAddress, ClientServerNI)
- Create a Connection that is connected to a specified remote service.
-
doPings()
- Send Ping packets to all peer processes, and check whether the Pings we sent
last time have elicited Pong in response.
-
find(int)
- Look up a connection, given its connection ID number.
-
getInputStream()
- Get an InputStream that can be used to get data arriving on this Connection.
-
getOutPacketStream()
- Get an output stream that can be used for building a packet to send on this connection.
-
getOutputStream()
- Get an OutputStream that can be used to send data on this Connection.
-
getPacket()
- Get the next data packet that has arrived on this Connection.
-
getPeerAddress()
- Get the address of the other end of this connection.
-
handleAcceptPacket(PacketInputStream)
- Do the processing required to handle an Accept packet that arrived.
-
handleConnectPacket(PacketInputStream, ClientServerNI)
- Do the processing required to handle a Connect packet that arrived.
-
handleDataPacket(PacketInputStream)
- Do the processing required to handle a Data packet that arrived.
-
handleEodPacket(PacketInputStream)
- Do the processing required to handle an EndOfData packet that arrived.
-
handlePingPacket(PacketInputStream)
- Do the processing required to handle a Ping packet that arrived.
-
handlePongPacket()
- Do the processing required to handle a Pong packet that arrived.
-
sendEod()
- Send an EndOfData on this connection; this is like closing the outgoing side of the connection.
MaxPacketLength
static final int MaxPacketLength
- The maximum packet size that can be sent without triggering an exception in
a lower-level network interface.
csni
protected ClientServerNI csni
- The network interface used to send and receive packets on this connection.
inStream
protected InputStream inStream
- An input stream that can be given to applications that want to get data
that arrives on this connection.
outStream
protected OutputStream outStream
- An output stream that can be given to applications that want to send data
on this connection.
Connection
protected Connection()
- For use only by subclasses that override all methods.
Connection
protected Connection(NetAddress peerNetAddr,
ClientServerNI ni)
- Create a connection. The resulting Connection will not (yet) be connected to
another process. It is the responsibility of the caller to connect this object
to a remote process.
- Parameters:
- peerNetAddr - the address of the process that will eventually be at the
other end of the connection
- ni - the local network interface to use for sending and receiving packets
connect
static Connection connect(ServiceAddress sa,
ClientServerNI ni) throws IOException
- Create a Connection that is connected to a specified remote service.
- Parameters:
- sa - the address of the service to connect to
- ni - the local network interface to use for sending and receiving packets
- Returns:
- the connection that was created
- Throws: IOException
- some I/O error occurred
handleConnectPacket
static Connection handleConnectPacket(PacketInputStream pis,
ClientServerNI ni) throws IOException
- Do the processing required to handle a Connect packet that arrived.
- Parameters:
- pis - the arrived packet
- ni - the network interface it arrived on
- Throws: IOException
- some I/O error occurred
find
static synchronized Connection find(int num)
- Look up a connection, given its connection ID number.
- Parameters:
- num - the connection number to look up
- Returns:
- the connection with local ID number
num
, or null if there is no connection with that number
handleAcceptPacket
synchronized void handleAcceptPacket(PacketInputStream pis) throws IOException
- Do the processing required to handle an Accept packet that arrived.
- Parameters:
- pis - the arrived packet
- Throws: IOException
- some I/O error occurred
handleDataPacket
synchronized void handleDataPacket(PacketInputStream pis)
- Do the processing required to handle a Data packet that arrived.
- Parameters:
- pis - the arrived packet
- Throws: IOException
- some I/O error occurred
handleEodPacket
synchronized void handleEodPacket(PacketInputStream pis)
- Do the processing required to handle an EndOfData packet that arrived.
- Parameters:
- pis - the arrived packet
getPacket
synchronized PacketInputStream getPacket()
- Get the next data packet that has arrived on this Connection.
If no unread packets have arrived, the calling thread is blocked until a packet shows up.
- Returns:
- the next arrived data packet
getOutPacketStream
synchronized DataOutputStream getOutPacketStream() throws IOException
- Get an output stream that can be used for building a packet to send on this connection.
The packet will be sent automatically when the resulting stream is flushed.
- Returns:
- an output stream that can be used for building a new packet
- Throws: IOException
- some I/O error occurred
sendEod
synchronized void sendEod() throws IOException
- Send an EndOfData on this connection; this is like closing the outgoing side of the connection.
Once EndOfData has been sent, no further data can be sent on this connection.
The EndOfData marker will be put into the stream. The EndOfData marker will
be presented as an end-of-input-stream to the process on the other end of the
connection.
- Throws: IOException
- some I/O error occurred
getInputStream
public InputStream getInputStream()
- Get an InputStream that can be used to get data arriving on this Connection.
getOutputStream
public OutputStream getOutputStream()
- Get an OutputStream that can be used to send data on this Connection. Any data
written to the resulting stream will be sent through this Connection and will show
up on the InputStream on the other end.
The resulting OutputStream may buffer data, so you must call flush() if you want
to be sure your data has been sent.
- Returns:
- an OutputStream that can be used to send data through this Connection
getPeerAddress
public NetAddress getPeerAddress()
- Get the address of the other end of this connection.
- Returns:
- the address of the other end of this connection
doPings
static void doPings()
- Send Ping packets to all peer processes, and check whether the Pings we sent
last time have elicited Pong in response.
handlePingPacket
synchronized void handlePingPacket(PacketInputStream pis)
- Do the processing required to handle a Ping packet that arrived.
- Parameters:
- pis - the Ping packet
handlePongPacket
synchronized void handlePongPacket()
- Do the processing required to handle a Pong packet that arrived.
static void ()
- Set up a daemon thread to watch for broken connections.
All Packages Class Hierarchy This Package Previous Next Index