/* Communication Interface for Virtual Classroom Components. Complied in JDK 1.4.2 Usage: Step1: Create your component which implemnts Interface ComponentBase. Step2: Replace the ComponentMy with your class name in InterfaceServer::main(). Step3: start up Interface Server by java InterfaceServer Step4: Use Virtual remote which is also provided on the web to send message and get the feedback message. Enjoyed by flying, Jan 28, 2004. Any comments, please Email: flying@cs.pitt.edu */ import java.io.*; import java.net.*; import java.util.*; /* Class KeyValueList: List of (Key, Value) pair--the basic format of message keys: MsgID and Description are required for any messages MsgID 0-999 is reserved for system use. You MsgID could start from 1000. */ class KeyValueList { private Vector keys; private Vector values; /* Constructor */ public KeyValueList() { keys = new Vector(); values = new Vector(); } /* Look up the value given key, used in getValue() */ public int lookupKey(String strKey) { for(int i=0; i < keys.size(); i++) { String k = (String) keys.elementAt(i); if (strKey.equals(k)) return i; } return -1; } /* add new (key,value) pair to list */ public boolean addPair(String strKey,String strValue) { return (keys.add(strKey) && values.add(strValue)); } /* get the value given key */ public String getValue(String strKey) { int index=lookupKey(strKey); if (index==-1) return null; return (String) values.elementAt(index); } public void setValue(int index, String val) { if(index >= 0 && index < size()) values.set(index, val); } /* Show whole list */ public String toString() { String result = new String(); for(int i=0; i= 0 && msgID <= 10) compMy.processMsg(kvInput); else mEncoder.sendMsg(kvInput, client.getOutputStream()); } } while (kvInput != null); } catch (SocketException se) { System.out.println("Connection was Closed by Client"); } catch ( IOException ioe ) { System.out.println("SERVER INTERNAL ERROR: IOException: " + ioe.getMessage()); } catch (Exception ex) { System.out.println("Exception"); } } } }