44 |
static public boolean dbg = false; |
static public boolean dbg = false; |
45 |
static private void p(String s) { if(dbg) System.out.println(s); } |
static private void p(String s) { if(dbg) System.out.println(s); } |
46 |
static private void pa(String s) { System.out.println(s); } |
static private void pa(String s) { System.out.println(s); } |
47 |
|
static private String remoteaddress; |
48 |
|
|
49 |
/** A factory of application-specific HTTP connection objects. |
/** A factory of application-specific HTTP connection objects. |
50 |
* @see HTTPConnection |
* @see HTTPConnection |
51 |
*/ |
*/ |
55 |
* @throws IOException XXX |
* @throws IOException XXX |
56 |
*/ |
*/ |
57 |
public HTTPConnection newConnection(Socket s) throws IOException { |
public HTTPConnection newConnection(Socket s) throws IOException { |
58 |
p("httpconn"); |
p("httpconn"); |
59 |
return new HTTPConnection(s); |
return new HTTPConnection(s); |
60 |
} |
} |
61 |
} |
} |
65 |
* @throws IOException Indicates a problem with the socket |
* @throws IOException Indicates a problem with the socket |
66 |
*/ |
*/ |
67 |
protected HTTPConnection(Socket s) throws IOException { |
protected HTTPConnection(Socket s) throws IOException { |
68 |
this(s.getInputStream(), s.getOutputStream()); |
this(s.getInputStream(), s.getOutputStream(), |
69 |
|
s.getInetAddress().toString().substring(1)); |
70 |
} |
} |
71 |
|
|
72 |
/** Create a new connection object. |
/** Create a new connection object. |
73 |
* @param is The input stream for this connection |
* @param is The input stream for this connection |
74 |
* @param os The output stream for this connection |
* @param os The output stream for this connection |
75 |
*/ |
*/ |
76 |
protected HTTPConnection(InputStream is, OutputStream os) { |
protected HTTPConnection(InputStream is, OutputStream os, String ipaddress) { |
77 |
this.is = is; |
this.is = is; |
78 |
this.os = os; |
this.os = os; |
79 |
|
this.remoteaddress = ipaddress; |
80 |
thread.start(); |
thread.start(); |
81 |
} |
} |
82 |
|
|
83 |
/** Close this connection forcefully. This ends the thread |
/** Close this connection forcefully. This ends the thread |
84 |
* handling this connection and sends a notice to the client if |
* handling this connection and sends a notice to the client if |
85 |
* necessary. */ |
* necessary. */ |
94 |
} |
} |
95 |
} |
} |
96 |
} |
} |
97 |
|
|
98 |
|
/** Return the IP-address of remote host */ |
99 |
|
|
100 |
|
public String getRemoteIPAddress() { |
101 |
|
|
102 |
|
return this.remoteaddress; |
103 |
|
|
104 |
|
} |
105 |
|
|
106 |
|
|
107 |
/** An end-of-connection hook. A subclass can override this |
/** An end-of-connection hook. A subclass can override this |
108 |
* method and thus be informed when the connection is closed for |
* method and thus be informed when the connection is closed for |
366 |
// XXX not only when dbg is on? |
// XXX not only when dbg is on? |
367 |
if(dbg) e.printStackTrace(); |
if(dbg) e.printStackTrace(); |
368 |
} |
} |
369 |
} |
} |
370 |
|
|
371 |
|
|
372 |
|
|
373 |
} |
} |