annotate src/myVncClient/HTTPConnectSocket.java @ 50:c07bec8c8617

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