a6eda45f099c40dcb75f85a464ad5aac6d419811
[org.ibex.io.git] / src / org / ibex / io / Connection.java
1 // Copyright 2004 Adam Megacz, see the COPYING file for licensing [LGPL]
2 package org.ibex.io;
3
4 import java.net.*;
5 import java.io.*;
6 import org.ibex.util.*;
7
8 /** a stream backed by a socket */
9 public class Connection extends Stream {
10     private final Socket s;
11     public final String vhost;
12     public Connection(Socket s, String vhost) { super(s); this.vhost = vhost; this.s = s; }
13     public void close()                       { try{s.close();}catch(Exception e){throw new StreamException(e);} super.close(); }
14     public int getLocalPort()                 { return s.getLocalPort(); }
15     public InetAddress getLocalAddress()      { return ((InetSocketAddress)s.getLocalSocketAddress()).getAddress(); }
16     public int getRemotePort()                { return s.getPort(); }
17     public InetAddress getRemoteAddress()     { return ((InetSocketAddress)s.getRemoteSocketAddress()).getAddress(); }
18     public String getRemoteHostname()         { return getRemoteAddress().getHostName(); }
19     public String getVirtualHost()            { return vhost; }
20     public void setTimeout(int ms)            { try { s.setSoTimeout(ms); } catch (Exception e){throw new StreamException(e); }}
21     public void setTcpNoDelay(boolean delay)  { try { s.setTcpNoDelay(delay);}catch(Exception e){throw new StreamException(e); }}
22 }