annotate src/myVncProxy/HTTPConnectSocket.java @ 0:3cb9db416529

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