org.npsnet.xrti
Class InternetMessageChannel

java.lang.Object
  extended byorg.npsnet.xrti.MessageChannel
      extended byorg.npsnet.xrti.InternetMessageChannel

public class InternetMessageChannel
extends MessageChannel

An Internet message channel. Uses TCP for reliable/in-order message delivery and UDP for unreliable/out-of-order delivery.

Author:
Andrzej Kapolka

Field Summary
private static int MAXIMUM_PACKET_SIZE
          The maximum packet size for the best-effort component of this channel.
private  java.net.SocketAddress packetAddress
          The address for outgoing packets.
private  java.net.Socket tcpSocket
          The TCP socket, for reliable transportation.
private  java.net.DatagramSocket udpSocket
          The UDP socket, for best-effort transportation.
 
Constructor Summary
InternetMessageChannel(java.net.Socket federateSocket)
          Constructor for channels from federates.
InternetMessageChannel(java.lang.String executiveHost, int executivePort)
          Constructor for channels to the XRTI Executive.
 
Method Summary
 void close()
          Closes this channel.
 java.io.InputStream getInputStream()
          Returns the InputStream corresponding to the reliable component of this channel.
 int getMaximumPacketSize()
          Returns the maximum packet size supported by the best-effort component of this channel.
 java.io.OutputStream getOutputStream()
          Returns the OutputStream corresponding to the reliable component of this channel.
 boolean isClosed()
          Checks whether or not this channel is closed.
 void receivePacket(java.net.DatagramPacket packet)
          Receives a packet through the best-effort component of this channel.
 void sendPacket(java.net.DatagramPacket packet)
          Sends a packet through the best-effort component of this channel.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAXIMUM_PACKET_SIZE

private static final int MAXIMUM_PACKET_SIZE
The maximum packet size for the best-effort component of this channel.

See Also:
Constant Field Values

tcpSocket

private java.net.Socket tcpSocket
The TCP socket, for reliable transportation.


udpSocket

private java.net.DatagramSocket udpSocket
The UDP socket, for best-effort transportation.


packetAddress

private java.net.SocketAddress packetAddress
The address for outgoing packets.

Constructor Detail

InternetMessageChannel

public InternetMessageChannel(java.lang.String executiveHost,
                              int executivePort)
                       throws java.io.IOException
Constructor for channels to the XRTI Executive.

Parameters:
executiveHost - the host name of the XRTI Executive
executivePort - the port number of the XRTI Executive
Throws:
java.io.IOException - if an error occurs

InternetMessageChannel

public InternetMessageChannel(java.net.Socket federateSocket)
                       throws java.io.IOException
Constructor for channels from federates.

Parameters:
federateSocket - the newly accepted federate socket
Throws:
java.io.IOException - if an error occurs
Method Detail

getMaximumPacketSize

public int getMaximumPacketSize()
Returns the maximum packet size supported by the best-effort component of this channel.

Specified by:
getMaximumPacketSize in class MessageChannel
Returns:
the maximum packet size, in bytes

sendPacket

public void sendPacket(java.net.DatagramPacket packet)
                throws java.io.IOException
Sends a packet through the best-effort component of this channel.

Specified by:
sendPacket in class MessageChannel
Parameters:
packet - the packet to send
Throws:
java.io.IOException - if an error occurs

receivePacket

public void receivePacket(java.net.DatagramPacket packet)
                   throws java.io.IOException
Receives a packet through the best-effort component of this channel. Blocks until a packet is available.

Specified by:
receivePacket in class MessageChannel
Parameters:
packet - the object to contain the received packet
Throws:
java.io.IOException - if an error occurs

getInputStream

public java.io.InputStream getInputStream()
                                   throws java.io.IOException
Returns the InputStream corresponding to the reliable component of this channel.

Specified by:
getInputStream in class MessageChannel
Returns:
this channel's input stream
Throws:
java.io.IOException - in an error occurs

getOutputStream

public java.io.OutputStream getOutputStream()
                                     throws java.io.IOException
Returns the OutputStream corresponding to the reliable component of this channel.

Specified by:
getOutputStream in class MessageChannel
Returns:
this channel's output stream
Throws:
java.io.IOException - if an error occurs

close

public void close()
           throws java.io.IOException
Closes this channel.

Specified by:
close in class MessageChannel
Throws:
java.io.IOException - if an error occurs

isClosed

public boolean isClosed()
Checks whether or not this channel is closed.

Specified by:
isClosed in class MessageChannel
Returns:
true if this channel has been closed, false otherwise