All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class AcmeNet.Assn2.ClientServerNI

AcmeNet.Assn2.ClientServerNI

public class ClientServerNI
A network interface that supports client-server communication.

See Also:
Service, Connection

Constructor Index

 o ClientServerNI()
Create a ClientServerNI at any available address.
 o ClientServerNI(NetAddress)
Create a ClientServerNI at a specified address.

Method Index

 o bindService(int, Service)
Bind a service to a local service number.
 o connect(ServiceAddress)
Connect to a remote service.
 o enable()
The first call to this method "turns on" the processing of incoming packets.
 o getAddress()
Get the address of this ClientServerNI
 o getOutPacketStream(NetAddress)
Get a DataOutputStream that can be used to build a packet that will be sent via the underlying ReliableNI.
 o run()
Called by a daemon thread.
 o sendPing(NetAddress, int)
Send a Ping packet.
 o sendPong(NetAddress, int)
Send a Pong packet.
 o unbindService(int)
Unbind a service.

Constructors

 o ClientServerNI
 public ClientServerNI()
Create a ClientServerNI at any available address.

 o ClientServerNI
 public ClientServerNI(NetAddress requiredAddress) throws AddressUnavailableException
Create a ClientServerNI at a specified address.

Parameters:
requiredAddress - the address to use
Throws: AddressUnavailableException
the requested address was not available

Methods

 o getAddress
 public NetAddress getAddress()
Get the address of this ClientServerNI

Returns:
s the address of this ClientServerNI
 o enable
 public synchronized void enable()
The first call to this method "turns on" the processing of incoming packets. Before this method is called, all incoming packets are accumulated; when this method is called, all accumulated packets are processed. Subsequent packets are processed immediately upon their arrival.

Multiple calls to this method are allowed, but only the first one has any effect.

 o connect
 public Connection connect(ServiceAddress sa) throws IOException
Connect to a remote service.

Parameters:
sa - the address of the service to connect to
Returns:
a Connection to the requested service, or null if no connection could be made
Throws: IOException
some I/O error occurred
 o bindService
 public synchronized void bindService(int serviceNum,
                                      Service service) throws AlreadyBoundException
Bind a service to a local service number. This allows remote processes to connect to the service by specifying its NetAddress and service number.

Parameters:
serviceNum - the service number to bind to
service - the service to bind to that number
Throws: AlreadyBoundException
some other service is already bound to that serviceNumber
 o unbindService
 public synchronized void unbindService(int serviceNum)
Unbind a service. If there is no service bound at the requested number, do nothing.

Parameters:
serviceNum - the service number which should be unbound
 o run
 public void run()
Called by a daemon thread. This method is responsible for grabbing incoming packets and doing whatever processing is required.

 o getOutPacketStream
 DataOutputStream getOutPacketStream(NetAddress dest)
Get a DataOutputStream that can be used to build a packet that will be sent via the underlying ReliableNI. This method is for internal use and should not be called by clients.

Parameters:
the - destination of the newly created packet
Returns:
an output stream that can be used to build the packet
 o sendPing
 void sendPing(NetAddress peerAddr,
               int peerConnNum) throws IOException
Send a Ping packet.

Parameters:
peerAddr - the address to send the packet to
peerConnNum - the remote connection number that is being pinged
Throws: IOException
some I/O error occurred
 o sendPong
 void sendPong(NetAddress peerAddr,
               int peerConnNum) throws IOException
Send a Pong packet.

Parameters:
peerAddr - the address to send the packet to
peerConnNum - the remote connection number that is being ponged
Throws: IOException
some I/O error occurred

All Packages  Class Hierarchy  This Package  Previous  Next  Index