import java.io.*;
import java.net.*;
import java.applet.*;
import java.awt.*;

public class Client extends Applet
{
	static final int MYPORT = 6700;
	String instring = "No string yet", outstring = "Nothing yet";

	public void init()
	{
		
		add("South", new Button ("Get the time"));
		resize (250, 50);
	}

	void run_socket()
	{
		Socket s = null;
		try
		{
			s = new Socket(getCodeBase().getHost(), MYPORT);
			DataInputStream sinstream = new 
				DataInputStream(s.getInputStream());
			PrintStream soutstream = new 
				PrintStream(s.getOutputStream());
			soutstream.println("hello");
	
			outstring = sinstream.readLine();
			repaint();
			
			
		}
		catch (IOException e) 
			{System.err.println(e);}
		finally{
			try{ if (s != null) s.close();}
			catch (IOException e) {}
		}
	}
	public boolean action (Event e, Object o)
	{
		if (e.target instanceof Button)
		{
			run_socket();
			return true;
		}
		else 
		{
			return false;
		}
	}
	public void paint (Graphics g)
	{
		g.drawString(outstring, 10, 50);
	}
}
