Skip to content

Instantly share code, notes, and snippets.

@sakshamgurung
Created February 7, 2022 15:03
Show Gist options
  • Save sakshamgurung/839a474e868f23a6ecd681162abffdaa to your computer and use it in GitHub Desktop.
Save sakshamgurung/839a474e868f23a6ecd681162abffdaa to your computer and use it in GitHub Desktop.
Webserver class
// Inside WebServer.java file
public class WebServer{
public static void main (String args[]) throws IOException NoSuchAlgorithmException {
int serverPort = 9090;
// allocating resources for server's socket and assigning a port number
ServerSocket listenSocket = new ServerSocket(serverPort);
try{
System.out.println("Server program started...");
while(true) {
// listening to the assigned port number and accepting
// new client connection
System.out.println("\nListening for new connection...");
Socket clientSocket = listenSocket.accept();
System.out.println("\nA client is connected.....");
// Initializing 'Connection' class with
// client's socket address
Connection c = new Connection(clientSocket);
}
} catch(IOException e) {
System.out.println("Listen error:" + e.getMessage());
} finally{
listenSocket.close();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment