Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.net.*;
- import java.io.*;
- import java.lang.*;
- public class main {
- ServerSocket serverSocket = null;
- Socket clientSocket = null;
- public static SocketThread client;
- public static void main(String[] args) throws IOException
- {
- //Begins program.
- System.out.println(" ########################################");
- System.out.println(" # #");
- System.out.println(" # NexoGroup Chat Relay Server (CRS) #");
- System.out.println(" # BETA 1 #");
- System.out.println(" # #");
- System.out.println(" ########################################\n\n");
- int listenPort = 9898;
- System.out.println("Starting server on port " + listenPort +".");
- //Attempts to start listening on port 9898.
- try
- {
- ServerSocket serverSocket = new ServerSocket(listenPort);
- System.out.println("Server started successfully.");
- //Server started, now the client acceptance.
- while(true)
- {
- try
- {
- Socket clientSocket = serverSocket.accept();
- System.out.println("A client has connected successfully from: " + clientSocket.getInetAddress());
- SocketThread client = new SocketThread(clientSocket);
- client.start();
- }
- catch (IOException e)
- {
- System.err.println("Client unable to connect.");
- }
- }
- }
- catch (IOException e)
- {
- System.err.println("Server unable to bind to port.");
- System.exit(-1);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement