Advertisement
Guest User

Main ChatRelayCode

a guest
Apr 1st, 2012
845
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.94 KB | None | 0 0
  1. import java.net.*;
  2. import java.io.*;
  3. import java.lang.*;
  4. public class main {
  5.     ServerSocket serverSocket = null;
  6.     Socket clientSocket = null;
  7.     public static SocketThread client;
  8.     public static void main(String[] args) throws IOException
  9.     {
  10.          //Begins program.
  11.          System.out.println("                 ########################################");
  12.          System.out.println("                 #                                      #");
  13.          System.out.println("                 #   NexoGroup Chat Relay Server (CRS)  #");
  14.          System.out.println("                 #                BETA 1                #");
  15.          System.out.println("                 #                                      #");
  16.          System.out.println("                 ########################################\n\n");
  17.          int listenPort = 9898;
  18.          System.out.println("Starting server on port " + listenPort +".");
  19.          
  20.          //Attempts to start listening on port 9898.
  21.          try
  22.          {
  23.              ServerSocket serverSocket = new ServerSocket(listenPort);
  24.              System.out.println("Server started successfully.");
  25.              //Server started, now the client acceptance.
  26.              while(true)
  27.              {
  28.                  try
  29.                  {
  30.                      Socket clientSocket = serverSocket.accept();
  31.                      System.out.println("A client has connected successfully from: " + clientSocket.getInetAddress());
  32.                      SocketThread client = new SocketThread(clientSocket);
  33.                      client.start();
  34.                  }
  35.                  catch (IOException e)
  36.                  {
  37.                      System.err.println("Client unable to connect.");
  38.                  }
  39.              }
  40.          }
  41.          catch (IOException e)
  42.          {
  43.              System.err.println("Server unable to bind to port.");
  44.              System.exit(-1);
  45.          }
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement