24
|
1 package myVncProxy;
|
0
|
2 //
|
|
3 // Copyright (C) 2002 Constantin Kaplinsky, Inc. All Rights Reserved.
|
|
4 //
|
|
5 // This is free software; you can redistribute it and/or modify
|
|
6 // it under the terms of the GNU General Public License as published by
|
|
7 // the Free Software Foundation; either version 2 of the License, or
|
|
8 // (at your option) any later version.
|
|
9 //
|
|
10 // This software is distributed in the hope that it will be useful,
|
|
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13 // GNU General Public License for more details.
|
|
14 //
|
|
15 // You should have received a copy of the GNU General Public License
|
|
16 // along with this software; if not, write to the Free Software
|
|
17 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
|
18 // USA.
|
|
19 //
|
|
20
|
|
21 //
|
|
22 // HTTPConnectSocket.java together with HTTPConnectSocketFactory.java
|
|
23 // implement an alternate way to connect to VNC servers via one or two
|
|
24 // HTTP proxies supporting the HTTP CONNECT method.
|
|
25 //
|
|
26
|
|
27 import java.net.*;
|
|
28 import java.io.*;
|
|
29
|
|
30 class HTTPConnectSocket extends Socket {
|
|
31
|
|
32 public HTTPConnectSocket(String host, int port,
|
|
33 String proxyHost, int proxyPort)
|
|
34 throws IOException {
|
|
35
|
|
36 // Connect to the specified HTTP proxy
|
|
37 super(proxyHost, proxyPort);
|
|
38
|
|
39 // Send the CONNECT request
|
|
40 getOutputStream().write(("CONNECT " + host + ":" + port +
|
|
41 " HTTP/1.0\r\n\r\n").getBytes());
|
|
42
|
|
43 // Read the first line of the response
|
|
44 DataInputStream is = new DataInputStream(getInputStream());
|
|
45 String str = is.readLine();
|
|
46
|
|
47 // Check the HTTP error code -- it should be "200" on success
|
|
48 if (!str.startsWith("HTTP/1.0 200 ")) {
|
|
49 if (str.startsWith("HTTP/1.0 "))
|
|
50 str = str.substring(9);
|
|
51 throw new IOException("Proxy reports \"" + str + "\"");
|
|
52 }
|
|
53
|
|
54 // Success -- skip remaining HTTP headers
|
|
55 do {
|
|
56 str = is.readLine();
|
|
57 } while (str.length() != 0);
|
|
58 }
|
|
59 }
|
|
60
|