예제 #1
0
파일: Main.java 프로젝트: LaVloZ/tp-chat
  public static void main(String[] args) throws IOException {
    Server server = new Server(PORT);
    Socket client = server.listen();

    ChatDialog chat = new ChatDialog(client);
    chat.pack();
    SwingUtilities.invokeLater(() -> chat.setVisible(true));
    chat.start();
    System.exit(0);
  }
예제 #2
0
  /**
   * Constructor, makes a new server listening on specified port.
   *
   * @param port The port to listen on.
   */
  public Server(int port) {
    clientcounter = 0;
    shutdown = false;
    try {
      serversock = new ServerSocket(port);
    } catch (IOException e) {
      System.out.println("Could not create server socket.");
      return;
    }
    /* Server socket open, make a vector to store active threads. */
    serverthreads = new Vector<ServerThread>(0, 1);

    /* Output connection info for the server */
    System.out.println(
        "Server IP address: " + serversock.getInetAddress().getHostAddress() + ",  port " + port);

    /* listen on the socket for connections. */
    listen();
  }
예제 #3
0
  public static void main(String[] args) {
    parseCommandLine(args);

    DebugStream debug;
    try {
      debug = new DebugStream("server.debug");
    } catch (IOException e) {
      System.err.println("Couldn't open debug log file. Exiting.");
      e.printStackTrace();
      return;
    }

    Config config = new Config(debug);
    // config.read();
    // readAbilities();

    // initSignals();

    // initGame();

    Server server = new Server(config, debug);
    server.listen();
  }
예제 #4
0
 @Override
 public CompletableFuture<Void> listen(Address address, Consumer<Connection> listener) {
   Assert.notNull(address, "address");
   Assert.notNull(listener, "listener");
   return local.listen(address, listener).thenCompose(v -> remote.listen(address, listener));
 }