package yoonforh.generic; /* * Copyright (c) 1996 Yoon Kyung Koo. All Rights Reserved. * * GenericClient.java * Author: Yoon Kyung Koo (yoonforh@interpia.net, http://interpia.net/~yoonforh) * Creation Date: 10/24/96 * UPDATE HSITORY * Update: 01/03/97 * Version: 0.99a (for JDK 1.02 API) * Update: 10/25/96 * Version: 0.99 (for JDK 1.02 API) */ import java.io.*; import java.net.*; public class GenericClient { private String ServerHost; // ¼­¹öÀÇ ÀÎÅÍ³Ý ÁÖ¼Ò¸¦ ÁöÁ¤ÇÑ´Ù. private int nServerPort; // ¼­¹öÀÇ Æ÷Æ®¸¦ ÁöÁ¤ÇÑ´Ù. private Socket connection=null; private DataInputStream input = null; // PrintStream output = null; // there's a bug in the method PrintStream()! private DataOutputStream output = null; GenericClient(String szHost, int nPort) { ServerHost=szHost; nServerPort=nPort; } public DataInputStream getInput() { return input; } public DataOutputStream getOutput() { return output; } public int endSession() { try { connection.close(); // ¿¹¿Ü°¡ ¹ß»ýÇÏ¸é ¿¬°áµÈ ¼ÒÄÏÀ» ´Ý´Â´Ù. } catch(Exception e) { System.err.println(e.toString()); return -1; } return 0; } public int init(String szData) { try { connection = new Socket(ServerHost, nServerPort); } catch(Exception e) { System.err.println(e.toString()); return -1; } try { // ÁöÁ¤µÈ ÁÖ¼Ò¿Í Æ÷Æ®¸¦ ÀÌ¿ëÇÏ¿© ¼ÒÄÏÀ» »ý¼ºÇÑ ÈÄ ¼­¹ö¿¡ ¿¬°á±îÁö ÇÑ´Ù. input = new DataInputStream(new BufferedInputStream(connection.getInputStream())); // ¿¬°áµÈ ¼ÒÄÏ¿¡¼­ ÀÔ·Â ½ºÆ®¸²À» ¾ò´Â´Ù. // output = new PrintStream(server.getOutputStream()); output = new DataOutputStream(new BufferedOutputStream(connection.getOutputStream())); // ¿¬°áµÈ ¼ÒÄÏ¿¡¼­ ¾òÀº Ãâ·Â ½ºÆ®¸²À¸·Î PrintStream ÀνºÅϽº¸¦ »ý¼ºÇÑ´Ù. if ( !GenericTool.sendMessage( output, "WORKTYPE", szData )) { System.err.println("Send WORKTYPE message error"); return -1; } if ( !( (GenericTool.getMessage( input, "RESPONSE" )).equals("ACCEPT") ) ) { System.err.println("Received wrong message"); return -1; } } catch(Exception e) { System.err.println(e.toString()); try { connection.close(); // ¿¹¿Ü°¡ ¹ß»ýÇÏ¸é ¿¬°áµÈ ¼ÒÄÏÀ» ´Ý´Â´Ù. } catch(Exception ex) { System.err.println(ex.toString()); return -1; } return -1; } return 0; } // end of init() }