pygar.MessageServer
Class Server

java.lang.Object
  extended by pygar.MessageServer.Server

public class Server
extends java.lang.Object

The server is a stand-alone program that runs connected to the network. It accepts connections from clients who wish to exchange pygar.communication.Pmessage messages between themselves but who are unable to contact each other directly. Typically, this situation occurs in test networks with intervening NAT routing. This program verifies the identities of the parties and provides services only to known clients. Messages are simply forwarded as quickly as possible.

Limitations

The server is very simple and does not have features for high throughput. Therefore, clients should expect to find time blocked during conversations with the server. Moreover, there is a minimum of local buffering; therefore, an operation that forwards a message from one client to another will succeed only if both clients are active and connected to this server.

The server dedicates one and only one thread to each client; therefore, a client should send a single stream of messages to the server and should attempt to share the server connection between client threads. On the other hand, the server may send concurrent messages to a client in the event that there are messages to be forwarded concurrently from other clients. Therefore, each client should

Operation

It is important to realize that all traffic over the connection uses the PMessage format; therefore, each complete XML formatted message will reveal the sender's name and the name of the intended recipient. In addition, the message contains a "subject". The server examines these and no other fields. It checks the "subject" and if the subject is "ping", then the server interprets the request as follows.

The server interprets a ping request as a question about the possibility of forwarding a message from the sender the to specified recipient. It will respond with a acknowledgment message of "ok" if the forwarding is currently possible and "fail" if not. However, there is no attempt to actually communicate with the intended recipient. Two cases are of interest here. First, the server should always respond immediately because it has

When a client connects to the server, the success of the connection is signaled by the Java runtime. The client may then send a message to any other client that is also connected to the server.

Should it block the sender until recipient accepts the message? A GUI component reports the server status, current clients, client status, and traffic statistics. It is possible to suppress the GUI component with a command line argument, if desired. One designated client is authorized to request reports. Reports show who is connected and how long they have been idle. The report request looks like this: <report></report>. Note: at this stage of the development, the server *does not* verify identities. Note: we plan to have a thread that checks for inactive connections and removes them for garbage collection. Connection sequence: 1. Client requests and receives a connection. 2. Client sends a "ping" - this includes the client's ID. The message server verifies the ID and sends an "ack" with code "success" or it will simply break the connection. 3. Server records the connection under the client's name in clientMap. 4. If the client sends anything except a "ping" as the first message, the connection is broken, and if the client sends nothing the connection times out.


Nested Class Summary
 class Server.ClientDisplayLine
           
 
Field Summary
 javax.swing.JPanel center
           
 java.util.Vector<ConnectionHandler> clientList
           
 java.util.Map<java.lang.String,ConnectionHandler> clientMap
           
static int DEFAULT_HEIGHT
           
static int DEFAULT_WIDTH
           
 boolean hasGui
           
static int LINE_HEIGHT
           
 java.lang.String monitorName
           
 int serverPort
           
 Server theServer
           
 
Constructor Summary
Server(int portNumber, boolean gui, java.lang.String monitor)
          Create a server that watches for connections on port given by portNumber
 
Method Summary
static void main(java.lang.String[] args)
          The main program accepts command line parameters: clientPort -- port on which the server listens (default 8089) guiDisplay -- true if GUI is created for the server (default true) monitorName -- the name of the entity allowed to request server reports certDir -- the location of the certificates for authenticating senders (not implemented)
 java.lang.StringBuffer reportAll()
          Write a report in XML detailing who is connected to the server and how long each has been idle.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

theServer

public Server theServer

center

public javax.swing.JPanel center

DEFAULT_WIDTH

public static final int DEFAULT_WIDTH
See Also:
Constant Field Values

DEFAULT_HEIGHT

public static final int DEFAULT_HEIGHT
See Also:
Constant Field Values

LINE_HEIGHT

public static final int LINE_HEIGHT
See Also:
Constant Field Values

serverPort

public int serverPort

hasGui

public boolean hasGui

monitorName

public java.lang.String monitorName

clientList

public java.util.Vector<ConnectionHandler> clientList

clientMap

public java.util.Map<java.lang.String,ConnectionHandler> clientMap
Constructor Detail

Server

public Server(int portNumber,
              boolean gui,
              java.lang.String monitor)
       throws java.net.UnknownHostException
Create a server that watches for connections on port given by portNumber

Parameters:
portNumber -
Throws:
java.net.UnknownHostException
Method Detail

reportAll

public java.lang.StringBuffer reportAll()
Write a report in XML detailing who is connected to the server and how long each has been idle. In operation, only authorized users may request a report. During testing, anyone can.

Returns:
StringBuffer

main

public static void main(java.lang.String[] args)
                 throws java.net.UnknownHostException
The main program accepts command line parameters: clientPort -- port on which the server listens (default 8089) guiDisplay -- true if GUI is created for the server (default true) monitorName -- the name of the entity allowed to request server reports certDir -- the location of the certificates for authenticating senders (not implemented)

Parameters:
args -
Throws:
java.net.UnknownHostException