FileDocCategorySizeDatePackage
NetLogServer.javaAPI DocExample2791Sat Jan 13 18:09:58 GMT 2001None

NetLogServer

public class NetLogServer extends Object
Threaded NetLog Server, pre-allocation schema.
author
Ian F. Darwin.

Fields Summary
public static final int
PORT
public static final int
NUM_THREADS
JFrame
theFrame
JTextArea
theTextArea
Constructors Summary
public NetLogServer(int port, int numThreads)
Constructor

		ServerSocket servSock;
		Socket clientSocket;

		try {
			servSock = new ServerSocket(PORT);

		} catch(IOException e) {
			/* Crash the server if IO fails. Something bad has happened */
			System.err.println("Could not create ServerSocket " + e);
			System.exit(1);
			return;	/*NOTREACHED*/
		}

		// Build the GUI - must be before Handler constructors!
		theFrame  = new JFrame("NetLog Server");
		theTextArea = new JTextArea(24, 80);
		theTextArea.setEditable(false);
		theTextArea.setBorder(BorderFactory.createTitledBorder("NetLogServer"));
		theFrame.getContentPane().add(new JScrollPane(theTextArea));

		// Now start the Threads
		for (int i=0; i<numThreads; i++) {
			new Thread(new Handler(servSock, i)).start();
		}

		theFrame.pack();
		theFrame.setVisible(true);
		theFrame.addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent we) {
				System.exit(0);
			}
		});

	
Methods Summary
public synchronized voidlog(int tid, java.lang.String s)

		StringBuffer sb = new StringBuffer();
		sb.append(tid);
		sb.append(": ");

		if (s == null) {
			sb.append("(null)");
		}
		else if (s.length() == 0) {
			sb.append("(null string)");
		}
		else
			sb.append(s);

		sb.append('\n");
		theTextArea.append(sb.toString());
		theTextArea.setCaretPosition(theTextArea.getText().length());
		theFrame.toFront();
	
public static voidmain(java.lang.String[] av)
Main method, to start the servers.


	       
	    
	
		new NetLogServer(PORT, NUM_THREADS);