Jump to content
	public static void main(String argv[]) throws Exception {
		
		try {
			// Create listener socket
			ServerSocket serverSocket = new ServerSocket(port);
			while(true){
		    	Socket clientSocket = serverSocket.accept(); 
				HttpRequest request = new HttpRequest(clientSocket);
				Thread thread = new Thread(request);
				thread.start();
			}
		}
		catch (Exception e) {
	    	System.err.println(e.getMessage());
	    }
	}

So I'm doing assignment for my networking course and I need to make a multi-threaded webserver to handle multiple clients and/or requests in parallel. The issue I have is that whenever I try to access this local webserver through my browser, it basically executes the run() function in HttpRequest twice for whatever reason and I can't seem to figure out why. Can anyone shed some light?  

Intel® Core™ i7-12700 | GIGABYTE B660 AORUS MASTER DDR4 | Gigabyte Radeon™ RX 6650 XT Gaming OC | 32GB Corsair Vengeance® RGB Pro SL DDR4 | Samsung 990 Pro 1TB | WD Green 1.5TB | Windows 11 Pro | NZXT H510 Flow White
Sony MDR-V250 | GNT-500 | Logitech G610 Orion Brown | Logitech G402 | Samsung C27JG5 | ASUS ProArt PA238QR
iPhone 12 Mini (iOS 18.3) | iPhone 15 (iOS 18.3.1) | KZ AZ09 Pro x KZ ZSN Pro X | Sennheiser HD450bt
Intel® Core™ i7-1265U | Kioxia KBG50ZNV512G | 16GB DDR4 | Windows 11 Enterprise | HP EliteBook 650 G9
Intel® Core™ i5-8520U | WD Blue M.2 250GB | 1TB Seagate FireCuda | 16GB DDR4 | Windows 11 Home | ASUS Vivobook 15 
Intel® Core™ i7-3520M | GT 630M | 16 GB Corsair Vengeance® DDR3 |
Samsung 850 EVO 250GB | macOS Catalina | Lenovo IdeaPad P580

Link to comment
https://linustechtips.com/topic/896915-multi-threaded-tcp-connection-request/
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×