initial import
[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 int getLocalPort()                 { return s.getLocalPort(); }
14     public int getRemotePort()                { return s.getPort(); }
15     public InetAddress getRemoteAddress()     { return ((InetSocketAddress)s.getRemoteSocketAddress()).getAddress(); }
16     public String getRemoteHostname()         { return getRemoteAddress().getHostName(); }
17     public String getVirtualHost()            { return vhost; }
18     public void setTimeout(int ms)            { try { s.setSoTimeout(ms); } catch (Exception e){throw new StreamException(e); }}
19     public void setTcpNoDelay(boolean delay)  { try { s.setTcpNoDelay(delay);}catch(Exception e){throw new StreamException(e); }}
20 }