| Home >> All >> org >> zazof >> [ jteg Javadoc ] |
Source code: org/zazof/jteg/Connection.java
1 package org.zazof.jteg; 2 3 import java.net.*; 4 import java.io.*; 5 6 /** 7 * Provides a connection with the TEG server, provides a read and write method 8 * for communication with the server. This class may only be used by the TEGServer class. 9 * 10 * @author Jef De Geeter (jef@zazof.org) 11 * @author Yves Vandewoude (yves@stcham.org) 12 * @date July 2001 13 */ 14 15 class Connection{ 16 17 /** 18 Constructor of a connection 19 */ 20 Connection(){ 21 } 22 23 /** 24 makes an actual socket link with the server 25 */ 26 void makeConnection(String server, int port) throws IOException{ 27 sock = new Socket(server, port); 28 in = new BufferedReader(new InputStreamReader(sock.getInputStream())); 29 out = new BufferedWriter(new OutputStreamWriter(sock.getOutputStream())); 30 } 31 32 /** 33 Kills the current connection 34 */ 35 void killConnection() 36 throws IOException 37 { 38 sock.close(); 39 //in = null; 40 //out = null; 41 } 42 43 /** 44 writes the message to the server 45 */ 46 void writeToServer(String message) throws IOException{ 47 out.write(message); 48 out.newLine(); 49 out.flush(); 50 } 51 52 /** 53 reads a message from the server, this call blocks when now new 54 messages are available 55 */ 56 String readFromServer() throws IOException{ 57 return in.readLine(); 58 } 59 60 /* 61 private variables 62 */ 63 private BufferedWriter out; 64 private BufferedReader in; 65 private Socket sock; 66 }