source: trunk/packages/invirt-vnc-client/HTTPConnectSocketFactory.java @ 1727

Last change on this file since 1727 was 1334, checked in by broder, 16 years ago

sipb-xen-vnc-client -> invirt-vnc-client

File size: 2.4 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// HTTPConnectSocketFactory.java together with HTTPConnectSocket.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.applet.*;
27import java.net.*;
28import java.io.*;
29
30class HTTPConnectSocketFactory implements SocketFactory {
31
32  public Socket createSocket(String host, int port, Applet applet)
33    throws IOException {
34
35    return createSocket(host, port,
36                        applet.getParameter("PROXYHOST1"),
37                        applet.getParameter("PROXYPORT1"));
38  }
39
40  public Socket createSocket(String host, int port, String[] args)
41    throws IOException {
42
43    return createSocket(host, port,
44                        readArg(args, "PROXYHOST1"),
45                        readArg(args, "PROXYPORT1"));
46  }
47
48  public Socket createSocket(String host, int port,
49                             String proxyHost, String proxyPortStr)
50    throws IOException {
51
52    int proxyPort = 0;
53    if (proxyPortStr != null) {
54      try {
55        proxyPort = Integer.parseInt(proxyPortStr);
56      } catch (NumberFormatException e) { }
57    }
58
59    if (proxyHost == null || proxyPort == 0) {
60      System.out.println("Incomplete parameter list for HTTPConnectSocket");
61      return new Socket(host, port);
62    }
63
64    System.out.println("HTTP CONNECT via proxy " + proxyHost +
65                       " port " + proxyPort);
66    HTTPConnectSocket s =
67      new HTTPConnectSocket(host, port, proxyHost, proxyPort);
68
69    return (Socket)s;
70  }
71
72  private String readArg(String[] args, String name) {
73
74    for (int i = 0; i < args.length; i += 2) {
75      if (args[i].equalsIgnoreCase(name)) {
76        try {
77          return args[i+1];
78        } catch (Exception e) {
79          return null;
80        }
81      }
82    }
83    return null;
84  }
85}
86
Note: See TracBrowser for help on using the repository browser.