aleph.comm.udp
Class Packet

java.lang.Object
  |
  +--aleph.comm.udp.Packet

public class Packet
extends java.lang.Object
implements java.io.Serializable, Constants

See Also:
Serialized Form

Field Summary
 Packet next
           
 
Constructor Summary
Packet(int type)
          Constructor
 
Method Summary
 void append(byte[] b, int off, int len)
          Write bytes to packet.
 void append(int b)
          Write byte to packet.
 int available()
           
 boolean empty()
           
 int getAcknum()
           
 Address getAddress()
           
 int getSeqnum()
           
 int getType()
           
static void main(java.lang.String[] args)
           
 int read()
          Returns next byte from packet, or -1 if nothing left.
 int read(byte[] b, int off, int len)
          Reads up to len bytes of data into an array of bytes.
protected  void read4Bytes(int index, byte[] b)
           
protected  int readInt(int index)
           
static Packet receive(java.net.DatagramSocket socket)
          Receives and returns a packet from the network.
 void send(java.net.DatagramSocket socket, Address destination)
          Send the packet.
 void setAcknum(int ack)
           
 void setAddress(Address address)
           
 void setSeqnum(int seq)
           
 void setType(int type)
           
 java.lang.String toString()
           
protected  void write4Bytes(int index, byte[] b)
           
protected  void writeInt(int index, int v)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

next

public transient Packet next
Constructor Detail

Packet

public Packet(int type)
Constructor
Parameters:
type - what kind of packet?
See Also:
aleph.comm.datagram.Constants
Method Detail

main

public static void main(java.lang.String[] args)

getType

public int getType()

setType

public void setType(int type)

getSeqnum

public int getSeqnum()

setSeqnum

public void setSeqnum(int seq)

getAcknum

public int getAcknum()

setAcknum

public void setAcknum(int ack)

setAddress

public void setAddress(Address address)

getAddress

public Address getAddress()

available

public int available()
Returns:
number of unused data bytes in packet.

empty

public boolean empty()
Returns:
any data bytes in packet?

append

public void append(int b)
Write byte to packet. Beware: panics on overflow!
Parameters:
b - byte written

append

public void append(byte[] b,
                   int off,
                   int len)
Write bytes to packet. Beware: panics on overflow!
Parameters:
b - array of bytes
off - starting offset
len - number of bytes to write

read

public int read()
Returns next byte from packet, or -1 if nothing left.

read

public int read(byte[] b,
                int off,
                int len)
Reads up to len bytes of data into an array of bytes.
Parameters:
b - target array
off - offset in array
len - number of bytes
Returns:
number actually copied

send

public void send(java.net.DatagramSocket socket,
                 Address destination)
          throws java.io.IOException
Send the packet.
Parameters:
socket - This PE's socket
address - Destination address

receive

public static Packet receive(java.net.DatagramSocket socket)
                      throws java.io.InterruptedIOException
Receives and returns a packet from the network.
Parameters:
socket - Datagram socket on which to listen.

readInt

protected int readInt(int index)

writeInt

protected void writeInt(int index,
                        int v)

read4Bytes

protected void read4Bytes(int index,
                          byte[] b)

write4Bytes

protected void write4Bytes(int index,
                           byte[] b)

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object