Class BitSender
java.lang.Object
|
+----BitSender
- public class BitSender
- extends Object
NetRand Project
Software Engineering - CS536
University of Wisconsin - Milwaukee
Authors:
- Spring 1998 - Francis William Kasper
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.
-
bitBuffer
- internal buffer which holds bytes waiting to be sent
-
destHost
- structure which holds the address to send packets to
-
destPort
- the port to send packets to
-
sender
- socket which sends the datagram packets to server
-
BitSender()
- constructor for BitSender Class - uses
BitSenderPrefs for host and port info
-
BitSender(String, int)
- constructor for BitSender Class -
allows the caller to specify the destination host and port instead of using
the BitSenderPrefs object.
-
finalize()
- closes the DatagramSocket when the BitSender object is
disposed of.
-
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
-
SendByte(byte)
- adds a byte to the bitBuffer to hold before sending;
SendBuffer() is called to send the bytes to the destination server
-
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
sender
private DatagramSocket sender
- socket which sends the datagram packets to server
bitBuffer
private ByteVector bitBuffer
- internal buffer which holds bytes waiting to be sent
destHost
private InetAddress destHost
- structure which holds the address to send packets to
destPort
private int destPort
- the port to send packets to
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
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
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
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
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
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