a program that opens a server socket on the http port, port 80, and listens for requests from web browsers. You echo the requests, but don’t act on them.It has to be split in two classes.It is not showing any result.just displaying
output:
have opened port 80 locally
what is wrong on my code?
final int httpd = 80; ServerSocket ssock = new ServerSocket(httpd); System.out.println("have opened port 80 locally" ); Socket sock = ssock.accept(); sock.close(); System.out.println("client has made socket connection"); OneConnection client = new OneConnection(sock); String s = client.getRequest(); } catch (IOException e) { System.err.println(e); } } } OneConnection(Socket sock) throws IOException{ this.sock = sock; in = new BufferedReader(new InputStreamReader( sock.getInputStream() ) ); out = new DataOutputStream(sock.getOutputStream()); } String getRequest() throws IOException { String s=null; while ( (s=in.readLine())!= null) { System.out.println("got: "+ s); in.close(); out.close(); } return s; } }