/////// CgiUrl.java /////// import java.io.*; import java.net.*; // The msg to send is assumed to be correctly encoded // and formatted already public class CgiUrl implements CgiClient { public CgiUrl(String cgiurl) { try { URL urlobj = new URL(cgiurl); ser = urlobj.openConnection(); ser.setDoOutput(true); out = new PrintWriter(ser.getOutputStream()); } catch (MalformedURLException e) { JavaSystem.error(e); } catch (IOException e) { JavaSystem.error(e); } } /* posts the query msg, sets up input streams */ /* This method can be called only once */ public void postQuery(String msg) { try { if (out != null) { out.println(msg); out.close(); ins = ser.getInputStream(); in = new BufferedReader (new InputStreamReader(ins)); } } catch (IOException e) { JavaSystem.error(e); } } public TextLines textResponse() { if ( ins != null ) { TextLines from = new TextLines(); int len = from.input(ins); if ( len > -1 ) return from; } return null; } public String readNextLine() { try { return in.readLine(); } catch (IOException e) { JavaSystem.error(e); } return null; } public InputStream getInputStream() { return ins; } public void close() {} protected BufferedReader in; protected InputStream ins; protected PrintWriter out; protected URLConnection ser; }