Created
February 7, 2022 15:03
-
-
Save sakshamgurung/839a474e868f23a6ecd681162abffdaa to your computer and use it in GitHub Desktop.
Webserver class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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