// // PO_NetClient.java // // WELD Java Client Persistent Object Management Package // Copyright Francis Chan (fchan@ic.eecs.berkeley.edu), 1997 // University of California, Berkeley // // // This program is in the public domain. // Permission to use, copy, modify, and distribute this software // and its documentation for NON-COMMERCIAL purposes and // without fee is hereby granted, as long as credit is given. import java.net.*; import java.io.*; /** * * PO_NetClient Class * * This is a class which handles network socket connections and * closings. * It is also where the remote server and port number is specified. * * @version 1.3 Nov 1996 * @author Francis Chan */ public class PO_NetClient{ private OutputStream outStream = null; private String outStreamString = new String(); //private String server = "yoyodyne.eecs.berkeley.edu"; private String server; private Socket netSocket; /** * Port number for the data server */ private int port; private boolean debugFlag = true; /** * * Constructor of a PO_NetClient * @param server The name of the server to connect to * @param port The port of the server to connect to */ public PO_NetClient(String server, int port){ this.server = server; this.port = port; } /** * * Method that opens a socket connection to the designated server. * (set to yoyodyne.eecs.berkeley.edu, * port 701x right now) * Returns a socket if connection is completed, * null if not. * * Server and port number should/could be passed in in the future */ public Socket openConnection() { DEBUG("connecting to port: " + port + " ..."); try { netSocket = new Socket(server, port); DEBUG("Opened Port!!"); return netSocket; } catch (Exception e) { System.out.println("Port can't be opened"); e.printStackTrace(); return null; } } /** * * Closes the network connection */ public void closeConnection(Socket netSocket) { try { netSocket.close(); } catch (Exception e) { System.out.println("Socket can't be closed!"); } } /** * * Sends the message to the pre-designated network server * * @param message Message to be sent */ public void sendString(String message) { try { outStream = netSocket.getOutputStream(); } catch (Exception e) { System.out.println("can't open output stream"); e.printStackTrace(); } try { for (int i=0; i