/*
  * Listen on the specified address and port. Return a listener
  * that encapsulates the ServerSocket.
  */
 ListenKey startListening(String localaddress, int port) throws IOException {
   InetSocketAddress sa;
   if (localaddress == null) {
     sa = new InetSocketAddress(port);
   } else {
     sa = new InetSocketAddress(localaddress, port);
   }
   ServerSocket ss = new ServerSocket();
   ss.bind(sa);
   return new SocketListenKey(ss);
 }