Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
FVHTTP Server - ClientConnection.java

ClientConnection.java

Caricato da: Fraioveio
Scarica il programma completo

  1. package fvhttpserver;
  2.  
  3. import java.net.*;
  4. import java.io.*;
  5.  
  6. public class ClientConnection extends Thread {
  7.     public Socket s;
  8.     public boolean finish = false;
  9.     public ClientConnection(Socket s) {
  10.         this.s = s;
  11.     }
  12.    
  13.     @Override
  14.     public void run() {
  15.         try {
  16.             PrintStream out = new PrintStream(s.getOutputStream());
  17.             DataInputStream in = new DataInputStream(s.getInputStream());
  18.            
  19.             String query = "";
  20.             char tmp = ' ', tmpp = ' ';
  21.            
  22.             while(true) {
  23.                 tmp = (char) in.read();
  24.                 if(tmp == '\r' && tmpp == '\n')
  25.                     break;
  26.                
  27.                 tmpp = tmp;
  28.                
  29.                 query += tmp;
  30.             }
  31.            
  32.             ProcessQuery.process(query, out, s.getInetAddress().getHostAddress(), this);
  33.            
  34.             s.close();
  35.         } catch (IOException ex) {
  36.             System.out.println("[" + s.getInetAddress().getHostAddress() + "]: " + ex);
  37.         }
  38.        
  39.         finish = true;
  40.     }
  41. }