Class BitSender

java.lang.Object
   |
   +----BitSender

public class BitSender
extends Object

NetRand Project

Software Engineering - CS536

University of Wisconsin - Milwaukee

Authors:


File: BitSender.java

BitSender handles the communication channel between the client and the server. By using a DatagramSocket, the BitSender packages one byte of random bits into a DatagramPacket and sends it to the server. The server contains the BitPool class which accepts the incoming packets sent by all the clients.


Variable Index

 o bitBuffer
internal buffer which holds bytes waiting to be sent
 o destHost
structure which holds the address to send packets to
 o destPort
the port to send packets to
 o sender
socket which sends the datagram packets to server

Constructor Index

 o BitSender()
constructor for BitSender Class - uses BitSenderPrefs for host and port info
 o BitSender(String, int)
constructor for BitSender Class - allows the caller to specify the destination host and port instead of using the BitSenderPrefs object.

Method Index

 o finalize()
closes the DatagramSocket when the BitSender object is disposed of.
 o SendBuffer()
sends the contents of the bitBuffer one byte at a time by placing each byte in a DatagramPacket and sending it to the destination host
 o SendByte(byte)
adds a byte to the bitBuffer to hold before sending; SendBuffer() is called to send the bytes to the destination server
 o SendBytes(byte[])
adds a string of bytes to the bitBuffer to hold before sending; SendBuffer() is called to send the bits to the destination server

Variables

 o sender
 private DatagramSocket sender
socket which sends the datagram packets to server

 o bitBuffer
 private ByteVector bitBuffer
internal buffer which holds bytes waiting to be sent

 o destHost
 private InetAddress destHost
structure which holds the address to send packets to

 o destPort
 private int destPort
the port to send packets to

Constructors

 o BitSender
 public BitSender(String host,
                  int port) throws UnknownHostException, SocketException
constructor for BitSender Class - allows the caller to specify the destination host and port instead of using the BitSenderPrefs object.

Parameters:
host - - String containing the IP address of destination
port - - the destination port
Throws: UnknownHostException
if an unrecoginized hostname was given
Throws: SocketException
if failure to open DatagramSocket
 o BitSender
 public BitSender() throws UnknownHostException, SocketException
constructor for BitSender Class - uses BitSenderPrefs for host and port info

Throws: UnknowHostExeption
if an unrecoginized hostname was given
Throws: SocketException
if failure to open DatagramSocket

Methods

 o SendBytes
 public void SendBytes(byte newBytes[])
adds a string of bytes to the bitBuffer to hold before sending; SendBuffer() is called to send the bits to the destination server

Parameters:
newBytes - - array of bytes containing the new bits to add to buffer
 o SendByte
 public void SendByte(byte newByte)
adds a byte to the bitBuffer to hold before sending; SendBuffer() is called to send the bytes to the destination server

Parameters:
newByte - - the byte to add to the bitBuffer
 o SendBuffer
 private void SendBuffer()
sends the contents of the bitBuffer one byte at a time by placing each byte in a DatagramPacket and sending it to the destination host

 o finalize
 public void finalize() throws Throwable
closes the DatagramSocket when the BitSender object is disposed of.

Throws: Throwable
is thrown
Overrides:
finalize in class Object