package ix.search;

import java.util.*;
import java.io.IOException;
import java.io.*;
import java.net.*;

import javax.swing.JOptionPane;

import ix.icore.*;
import ix.ip2.*;
import ix.util.*;
import ix.util.lisp.*;

import org.jdom.*;
import org.jdom.input.*;

public class HandleConnection implements Runnable {


    // Connection preferences
     public Socket Supervisor = null;
     public BufferedReader input = null;
     public DataOutputStream output = null;

     public AgendaItem it;
	public HandleConnection(AgendaItem item)
	{
		this.it = item;

		try {

		this.Supervisor = new Socket("localhost",54000);
		this.input = new BufferedReader(new InputStreamReader(this.Supervisor.getInputStream()));
		this.output = new DataOutputStream(this.Supervisor.getOutputStream());

		}catch(UnknownHostException e){
			System.err.println("Trying to connect to unknown host: " + e);
		}
		catch(IOException e) 
		{
			System.err.println("IOException: " + e);
		}
	}

    public Socket returnSocket()
    {
	return Supervisor;
    }

    public BufferedReader returnBufferedReader()
    {
	return input;
    }	

    public DataOutputStream returnDataOutputStream()
    {
	return output;
    }

    public void run() {
	String Response;
	
	//We've reached this far without error
	if(Supervisor!=null && input!=null)
	{

		try {
		while((Response = this.input.readLine())!=null) {
			System.out.println(Response);
		}
	
		} catch(IOException e){}
	}

    }


}
