All pastes #957797 Raw Edit

Something

public text v1 · immutable
#957797 ·published 2008-03-26 05:56 UTC
rendered paste body
public class ConnectionHandler implements Runnable {
   
	private BufferedReader in;
    private PrintWriter out=null;
    Socket clientSocket=null;
    XMPPServer protocol;
    int id; 
    
    public ConnectionHandler(){	
    }
    
    public ConnectionHandler(Socket acceptedSocket, XMPPServer _protocol,int _id)
    {
        this.clientSocket = acceptedSocket;
        this.protocol = _protocol;
        id = _id;
        System.out.println("Accepted connection from client!");
        System.out.println("The client is from: " + acceptedSocket.getInetAddress() + ":" + acceptedSocket.getPort());
    }


 public void initialize() throws IOException
    {
        this.in = new BufferedReader(new InputStreamReader(this.clientSocket.getInputStream()));
        this.out = new PrintWriter(this.clientSocket.getOutputStream(), true);
        System.out.println("I/O initialized");
    }
    

 public boolean StreamRequest(User[] userList) throws IOException{
    	// First initialize the connection between sockets : 
    	try {
             this.initialize();
         }
         catch (IOException e) {
             System.out.println("Error in initializing I/O");
         }
        //String msg = this.in.readLine();
        // System.out.println(msg);
         try{
     		char[] buffer = new char[5000]; 
     		int charsRead = -2;
     		while (charsRead != -1)
     		{
     			charsRead = this.in.read(buffer);
     		}   
     		   System.out.println(charsRead);
     		   //String msg = new String(buffer, 0, charsRead);
     		   //System.out.println("Received:\n" + msg);
         }catch(Exception e){System.out.println(e);}