An application

This is a client-server application written in Java for Windows (a compiled .exe file).

Chat.java
SwingWindow.java
MenuFrame.java
MainPanel.java
TextPane.java



package app;

import java.net.*;

public class WriteServer {

  public static InetAddress host;
  public static int serverPort = 666;
  public static int clientPort = 999;
  public static int buffer_size = 1024;
  public static DatagramSocket ds;
  public static byte buffer[] = new byte[buffer_size];

  public static void main(String[] args) throws Exception {
    if (args.length == 1) {
      host = InetAddress.getByName(args[0]);
      ds = new DatagramSocket(serverPort);
      theServer();
    } else {
      ds = new DatagramSocket(clientPort);
      theClient();
    }
  }

  public static void theClient() throws Exception {
    System.out.println();
    System.out.println("============== CLIENT ==============");
    System.out.println(" HOST: " + InetAddress.getLocalHost());
    System.out.println("------------------------------------");
    System.out.println(" >>>>>>> WAIT FOR A MESSAGE <<<<<<< ");
    System.out.println("====================================");
    System.out.println();
    while (true) {
      DatagramPacket p = new DatagramPacket(buffer, buffer.length);
      ds.receive(p);
      System.out.println(new String(p.getData(), 0, p.getLength()));
    }
  }

  public static void theServer() throws Exception {
    System.out.println();
    System.out.println("============== SERVER ==============");
    System.out.println(" HOST: " + InetAddress.getLocalHost());
    System.out.println("-------------- CLIENT --------------");
    System.out.println(" HOST: " + host);
    System.out.println("------------------------------------");
    System.out.println(" >>>>>>>> TYPE YOUR MESSAGE <<<<<<< ");
    System.out.println("====================================");
    System.out.println();
    int pos = 0;
    while (true) {
      int c = System.in.read();
      switch (c) {
        case -1:
          System.out.println();
          System.out.println("========= SERVER HAS ENDED =========");
          System.out.println();
          return;
        case '\r':
          break;
        case '\n':
          ds.send(new DatagramPacket(buffer, pos, host, clientPort));
          pos = 0;
          break;
        default:
          buffer[pos++] = (byte) c;
      }
    }
  }
}