1 // Copyright 2000-2005 the Contributors, as shown in the revision logs.
2 // Licensed under the Apache Public Source License 2.0 ("the License").
3 // You may not use this file except in compliance with the License.
9 import org.ibex.util.*;
11 /** a stream backed by a socket */
12 public class Connection extends Stream {
13 private final Socket s;
14 public final String vhost;
15 public Connection(Socket s, String vhost) { super(s); this.vhost = vhost; this.s = s; }
16 protected Connection(InputStream i, OutputStream o) { super(i, o); vhost = null; s = null; }
17 public Socket getSocket() { return s; }
19 public int getLocalPort() { return s.getLocalPort(); }
20 public InetAddress getLocalAddress() { return ((InetSocketAddress)s.getLocalSocketAddress()).getAddress(); }
21 public int getRemotePort() { return s.getPort(); }
22 public InetAddress getRemoteAddress() { return ((InetSocketAddress)s.getRemoteSocketAddress()).getAddress(); }
23 public String getRemoteHostname() { return getRemoteAddress().getHostName(); }
24 public String getVirtualHost() { return vhost; }
25 public void setTimeout(int ms) { try { s.setSoTimeout(ms); } catch(IOException e) { ioe(e); } }
26 public void setTcpNoDelay(boolean delay) { try { s.setTcpNoDelay(delay); } catch(IOException e) { ioe(e); } }
28 /** never throws an exception */
29 public void close() { try{if (s!=null) s.close();}catch(Exception e){/*ignore*/} super.close(); }