Back to index

wims  3.65+svn20090927
Connection.java
Go to the documentation of this file.
00001 /*
00002 $Id: Connection.java,v 1.2 2003/02/18 11:48:48 sander Exp $
00003 */
00004 
00005 
00006 package fr.ove.utils;
00007 
00008 import java.io.*;
00009 import java.net.*;
00010 
00015 public class Connection implements ConnectionConfigurable {
00019     private Socket socket;
00020 
00024     private InputStream inputStream = null;
00025 
00029     private OutputStream outputStream = null;
00030 
00034     private String hostName;
00035 
00039     private int portNumber;
00040 
00045     public Connection() {
00046         this("localhost", 6666);
00047     }
00048 
00054     public Connection(String hostName, int portNumber) {
00055         this.hostName = hostName;
00056         this.portNumber = portNumber;
00057     }
00058 
00063     public void setHostName(String name) {
00064         hostName = name;
00065     }
00066 
00070     public String getHostName() {
00071         return hostName;
00072     }
00073 
00078     public void setPortNumber(int number) {
00079         portNumber = number;
00080     }
00081 
00085     public int getPortNumber() {
00086         return portNumber;
00087     }
00088 
00092     public void open() throws IOException {
00093               socket = new Socket(InetAddress.getByName(hostName), portNumber);
00094               inputStream = socket.getInputStream();
00095               outputStream = socket.getOutputStream();
00096     }
00097 
00102     public void open(Socket socket) throws IOException {
00103               this.socket = socket;
00104               hostName = socket.getInetAddress().getHostName();
00105               portNumber = socket.getPort();
00106               inputStream = socket.getInputStream();
00107               outputStream = socket.getOutputStream();
00108     }
00109 
00113     public boolean isOpened() {
00114         return ((outputStream != null) && (inputStream != null));
00115     }
00116 
00120     public void close() throws IOException {
00121         outputStream.close();
00122         inputStream.close();
00123         outputStream = null;
00124         inputStream = null;
00125     }
00126 
00130     public InputStream getInputStream() {
00131         return inputStream;
00132     }
00133 
00137     public OutputStream getOutputStream() {
00138         return outputStream;
00139     }
00140 }