source: branches/wsgi/packages/sipb-xen-vnc-client/code/HTTPConnectSocket.java @ 2525

Last change on this file since 2525 was 66, checked in by quentin, 17 years ago

Initial checkin of modified Java VNC viewer for use as remote console

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