Fibonacci Server


import java.net.*;
import java.io.*;


public class FibonacciServer {
  
  public final static int DEFAULT_PORT = 1597;
  
  public static void main(String[] args) {
    
    int port = DEFAULT_PORT;
    if (args.length > 0) { 
      try {
        port = Integer.parseInt(args[0]); 
      }
      catch (Exception e) {
      }
    }
    
    try {
      ServerSocket ss = new ServerSocket(port);
      while (true) {
        Socket client = ss.accept(); 
        // really need to limit the maximum number of connections
        FibonacciGenerator generator = new FibonacciGenerator(client);
        Thread t = new Thread(generator);
        t.start();
        System.out.println("Accepted a connection");
      }
      
      
    }
    catch (IOException e) {
      e.printStackTrace(); 
    }   
  
  } 
  
  
}

Previous | Next | Top | Cafe con Leche

Copyright 2000 Elliotte Rusty Harold
elharo@metalab.unc.edu
Last Modified March 4, 2000