Note that there are some explanatory texts on larger screens.

plurals
  1. POMultithreaded WebServer
    primarykey
    data
    text
    <p>Hi I`m trying to create a Multithreaded Webserver I have referred <a href="https://stackoverflow.com/questions/4910033/java-multithreaded-web-server-not-recieving-multiple-get-requests">Link 1</a> <a href="http://www.seas.gwu.edu/~cheng/6431/Projects/Project1WebServer/webserver.html" rel="nofollow noreferrer">Link 2</a> </p> <pre><code>import java.net.*; import java.io.*; public class WebServer { ServerSocket server; public WebServer() { try { server=new ServerSocket(3000); } catch (IOException ex) { System.out.println("exc in const "+ex.getMessage()); } } Socket client; BufferedReader br; Thread t=new Thread(new Runnable(){ @Override public void run() { try{ System.out.println(br.readLine()); } catch(Exception e){ System.out.println("exc is "+e); } } }); public void RUN(){ while(true){ try { client=server.accept(); System.out.println(client.getPort()); if(client!=null){ r=new BufferedReader(new InputStreamReader(client.getInputStream())); t.start(); } } catch (IOException ex) { System.out.println("ex is "+ex.getMessage()); } } } public static void main(String[] args) { WebServer webserver=new WebServer(); try { webserver.RUN(); } catch (Exception e) { System.out.println("main "+e); } } } </code></pre> <p>In the above code I keep getting a thread Illegal Access Exception so why do i keep getting this exception I want to open Multiple tabs in browser and open localhost:3000 then the Server Must print the http request and port number but this happens only for first Client and not the others it shows illegalThreadAccess Exception and the Program terminates</p> <p>Will greatly Appreciate if any pages are there that tell how to display some content in a Webbrowser.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload