package NET.worlds.scape; import NET.worlds.network.DNSLookup; import java.io.DataInputStream; import java.io.IOException; import java.io.PrintStream; import java.net.Socket; class CDDBConnection { private Socket sock; private PrintStream sockOut; private DataInputStream sockIn; private boolean readOnly; private boolean debug; public CDDBConnection(CDDBHost host, boolean debug) throws IOException { this.debug = debug; if (debug) { System.out.println("Contacting host " + host); } this.sock = new Socket(DNSLookup.lookup(host.getHost()), host.getPort()); CDDBLookup.markActivity(); this.sockOut = new PrintStream(this.sock.getOutputStream(), true); this.sockIn = new DataInputStream(this.sock.getInputStream()); String msg = this.recv(); if (msg.startsWith("200 ")) { this.readOnly = false; } else { if (!msg.startsWith("201 ")) { throw new IOException("Can't connect to " + host + ": " + msg); } this.readOnly = true; } } public String command(String command) throws IOException { this.send(command); return this.recv(); } public String readBody() throws IOException { String str = this.recv(); return str.equals(".") ? null : str; } public void close() { try { this.send("quit"); this.recv(); this.sock.close(); } catch (IOException var2) { } } private void send(String msg) throws IOException { if (this.debug) { System.out.println("--> " + msg); } this.sockOut.println(msg); CDDBLookup.markActivity(); } private String recv() throws IOException { String msg = this.sockIn.readLine(); CDDBLookup.markActivity(); if (this.debug) { System.out.println("<-- " + msg); } return msg; } }