Class RandomByteServer
java.lang.Object
|
+----java.lang.Thread
|
+----RandomByteServer
- public class RandomByteServer
- extends Thread
NetRand Project
Software Engineering - CS536
University of Wisconsin - Milwaukee
Authors:
- Spring 1998 - Francis William Kasper
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.
-
collectionPort
- port BitPool class should listen for client's data packets
-
entropy
- handles the collection and storage of random bytes
-
maxPoolSize
- maximum size of the byte pool
-
maxRequestSize
- maximum number of bytes a user can request at one time
-
poolParamSet
- flag for if the BitPool's parameters were set
-
requestParamSet
- flag for if the request parameters are set
-
serverPort
- port to listen for byte requests
-
serverQueueLength
- how many TCP connections to queue on the socket
-
theServer
- accepts requests for random bytes
-
RandomByteServer(ServerPrefs)
- constructor for the RandomByteServer class
-
initBitPool()
- initializes the BitPool object, and starts the BitPool Thread
-
initRandomByteServer()
- initializes the RandomByteServer, by calling initBitPool() and
initRequestServer()
-
initRequestServer()
- initializes the request server
-
main(String[])
- Run when the RandomByteServer is involked from the command line.
-
respondToRequest(String)
- handles a request for random bytes from the BitPool
-
run()
- overrides Thread run() method, waites for request connections over the
TCP socket.
-
setBitPoolParam(int, int, int)
- sets the BitPool's parameters
-
setRequestSocketParam(int, int)
- sets the parameters for the request server socket
theServer
private ServerSocket theServer
- accepts requests for random bytes
serverPort
private int serverPort
- port to listen for byte requests
serverQueueLength
private int serverQueueLength
- how many TCP connections to queue on the socket
requestParamSet
private boolean requestParamSet
- flag for if the request parameters are set
entropy
private BitPool entropy
- handles the collection and storage of random bytes
collectionPort
private int collectionPort
- port BitPool class should listen for client's data packets
maxPoolSize
private int maxPoolSize
- maximum size of the byte pool
maxRequestSize
private int maxRequestSize
- maximum number of bytes a user can request at one time
poolParamSet
private boolean poolParamSet
- flag for if the BitPool's parameters were set
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.
main
public static void main(String args[])
- Run when the RandomByteServer is involked from the command line.
Creates a RandomByteServer thread and calls start()
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
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.
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.
initBitPool
private boolean initBitPool()
- initializes the BitPool object, and starts the BitPool Thread
- Returns:
- true iff the BitPool was properly initialized, otherwise false
initRequestServer
private boolean initRequestServer()
- initializes the request server
- Returns:
- true iff the request server was properly initialized, otherwise false
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
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