Class RandomByteServer

java.lang.Object
   |
   +----java.lang.Thread
           |
           +----RandomByteServer

public class RandomByteServer
extends Thread

NetRand Project

Software Engineering - CS536

University of Wisconsin - Milwaukee

Authors:


File: RandomByteServer.java

The RandomByteServer handles TCP connections requesting a sequence of random bytes from the BitPool. When involked from the command line, the RandomByteServer accesses the ServerPrefs class to obtain the parameters for initializing the server. The server calls the BitPool class to handle the obtaining and storage of the random bytes. When the RandomByteServer gets a request over the socket, it gets the requested bytes from the BitPool class and sends then over the accepted TCP socket.


Variable Index

 o collectionPort
port BitPool class should listen for client's data packets
 o entropy
handles the collection and storage of random bytes
 o maxPoolSize
maximum size of the byte pool
 o maxRequestSize
maximum number of bytes a user can request at one time
 o poolParamSet
flag for if the BitPool's parameters were set
 o requestParamSet
flag for if the request parameters are set
 o serverPort
port to listen for byte requests
 o serverQueueLength
how many TCP connections to queue on the socket
 o theServer
accepts requests for random bytes

Constructor Index

 o RandomByteServer(ServerPrefs)
constructor for the RandomByteServer class

Method Index

 o initBitPool()
initializes the BitPool object, and starts the BitPool Thread
 o initRandomByteServer()
initializes the RandomByteServer, by calling initBitPool() and initRequestServer()
 o initRequestServer()
initializes the request server
 o main(String[])
Run when the RandomByteServer is involked from the command line.
 o respondToRequest(String)
handles a request for random bytes from the BitPool
 o run()
overrides Thread run() method, waites for request connections over the TCP socket.
 o setBitPoolParam(int, int, int)
sets the BitPool's parameters
 o setRequestSocketParam(int, int)
sets the parameters for the request server socket

Variables

 o theServer
 private ServerSocket theServer
accepts requests for random bytes

 o serverPort
 private int serverPort
port to listen for byte requests

 o serverQueueLength
 private int serverQueueLength
how many TCP connections to queue on the socket

 o requestParamSet
 private boolean requestParamSet
flag for if the request parameters are set

 o entropy
 private BitPool entropy
handles the collection and storage of random bytes

 o collectionPort
 private int collectionPort
port BitPool class should listen for client's data packets

 o maxPoolSize
 private int maxPoolSize
maximum size of the byte pool

 o maxRequestSize
 private int maxRequestSize
maximum number of bytes a user can request at one time

 o poolParamSet
 private boolean poolParamSet
flag for if the BitPool's parameters were set

Constructors

 o RandomByteServer
 public RandomByteServer(ServerPrefs prefs) throws ByteServerException
constructor for the RandomByteServer class

Parameters:
prefs - - ServerPrefs object
Throws: ByteServerException
if either the request socket or the BitPool parameters were not properly set.

Methods

 o main
 public static void main(String args[])
Run when the RandomByteServer is involked from the command line. Creates a RandomByteServer thread and calls start()

 o initRandomByteServer
 public void initRandomByteServer() throws ByteServerException
initializes the RandomByteServer, by calling initBitPool() and initRequestServer()

Throws: ByteServerException
if either the request server or the BitPool could not be initialized
 o setRequestSocketParam
 private boolean setRequestSocketParam(int reqPort,
                                       int reqPortQueue)
sets the parameters for the request server socket

Parameters:
reqPort - - the port to listen for random byte requests
reqPortQueue - - how many incoming TCP connections to queue
Returns:
true iff all the parameters were properly set, otherwise false.
 o setBitPoolParam
 private boolean setBitPoolParam(int collPort,
                                 int poolSize,
                                 int reqSize)
sets the BitPool's parameters

Parameters:
collPort - - the port to listen for client's data packets
poolSize - - the maximum byte size of the BitPool's byte buffer
reqSize - - the maximum number of bytes a user can request at on time
Returns:
true iff all the parameters were properly set, otherwise false.
 o initBitPool
 private boolean initBitPool()
initializes the BitPool object, and starts the BitPool Thread

Returns:
true iff the BitPool was properly initialized, otherwise false
 o initRequestServer
 private boolean initRequestServer()
initializes the request server

Returns:
true iff the request server was properly initialized, otherwise false
 o run
 public void run()
overrides Thread run() method, waites for request connections over the TCP socket. When a request is received, the respondToRequest() function is called to handle the request

Overrides:
run in class Thread
 o respondToRequest
 private byte[] respondToRequest(String request)
handles a request for random bytes from the BitPool

Parameters:
request - - string containing the number of bytes the user is requesting
Returns:
an array of bytes containing the number of bytes the user requested, or if the user's request was illegel, the byte array contains the appropriate error message