Guest User

Untitled

a guest
Jun 17th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. public void run() {
  2. try {
  3. System.out.println("Connection from "+socket.getRemoteSocketAddress());
  4. BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
  5. PrintStream out = new PrintStream(socket.getOutputStream());
  6.  
  7. while((line = input.readLine()) != null){
  8. System.out.println("SERVER: "+line);
  9.  
  10. if(!parser.execute(line, request)){
  11. System.out.println("here");
  12. response = handler.handle(request);
  13. String ret = response.toString();
  14. out.println(ret);
  15.  
  16. String connection = request.getConnection();
  17. if(connection.equals("close")){
  18. System.out.println("Connection terminated by client");
  19. break;
  20. }
  21. if(response.getClass()==Response404.class){
  22. System.out.println("Bad Request to: " + request.getRequestURI());
  23. break;
  24. }
  25. }
  26. System.out.println("END WHILE");
  27.  
  28. }
  29. // TODO: Send Connection Close message
  30. socket.close();
  31.  
  32.  
  33.  
  34.  
  35.  
  36. }catch (SocketException e){
  37. System.out.println("Socket closed by Client");
  38. }catch (IOException e) {
  39. // TODO Auto-generated catch block
  40. e.printStackTrace();
  41. }
  42.  
  43. // TODO Auto-generated method stub
  44.  
  45. }
Add Comment
Please, Sign In to add comment