annotate src/HTTPConnectSocketFactory.java @ 0:e04119c40b9b

upload all file of tighVNCClient
author e085711
date Tue, 12 Apr 2011 12:57:33 +0900
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
1 //
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
2 // Copyright (C) 2002 Constantin Kaplinsky, Inc. All Rights Reserved.
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
3 //
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
4 // This is free software; you can redistribute it and/or modify
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
5 // it under the terms of the GNU General Public License as published by
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
6 // the Free Software Foundation; either version 2 of the License, or
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
7 // (at your option) any later version.
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
8 //
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
9 // This software is distributed in the hope that it will be useful,
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
12 // GNU General Public License for more details.
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
13 //
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
14 // You should have received a copy of the GNU General Public License
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
15 // along with this software; if not, write to the Free Software
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
17 // USA.
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
18 //
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
19
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
20 //
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
21 // HTTPConnectSocketFactory.java together with HTTPConnectSocket.java
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
22 // implement an alternate way to connect to VNC servers via one or two
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
23 // HTTP proxies supporting the HTTP CONNECT method.
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
24 //
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
25
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
26 import java.applet.*;
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
27 import java.net.*;
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
28 import java.io.*;
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
29
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
30 class HTTPConnectSocketFactory implements SocketFactory {
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
31
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
32 public Socket createSocket(String host, int port, Applet applet)
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
33 throws IOException {
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
34
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
35 return createSocket(host, port,
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
36 applet.getParameter("PROXYHOST1"),
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
37 applet.getParameter("PROXYPORT1"));
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
38 }
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
39
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
40 public Socket createSocket(String host, int port, String[] args)
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
41 throws IOException {
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
42
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
43 return createSocket(host, port,
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
44 readArg(args, "PROXYHOST1"),
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
45 readArg(args, "PROXYPORT1"));
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
46 }
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
47
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
48 public Socket createSocket(String host, int port,
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
49 String proxyHost, String proxyPortStr)
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
50 throws IOException {
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
51
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
52 int proxyPort = 0;
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
53 if (proxyPortStr != null) {
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
54 try {
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
55 proxyPort = Integer.parseInt(proxyPortStr);
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
56 } catch (NumberFormatException e) { }
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
57 }
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
58
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
59 if (proxyHost == null || proxyPort == 0) {
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
60 System.out.println("Incomplete parameter list for HTTPConnectSocket");
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
61 return new Socket(host, port);
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
62 }
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
63
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
64 System.out.println("HTTP CONNECT via proxy " + proxyHost +
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
65 " port " + proxyPort);
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
66 HTTPConnectSocket s =
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
67 new HTTPConnectSocket(host, port, proxyHost, proxyPort);
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
68
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
69 return (Socket)s;
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
70 }
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
71
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
72 private String readArg(String[] args, String name) {
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
73
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
74 for (int i = 0; i < args.length; i += 2) {
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
75 if (args[i].equalsIgnoreCase(name)) {
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
76 try {
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
77 return args[i+1];
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
78 } catch (Exception e) {
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
79 return null;
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
80 }
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
81 }
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
82 }
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
83 return null;
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
84 }
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
85 }
e04119c40b9b upload all file of tighVNCClient
e085711
parents:
diff changeset
86