2 // Copyright (C) 2002 Constantin Kaplinsky, Inc. All Rights Reserved.
3 // Copyright 2007 MIT Student Information Processing Board
5 // This is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
10 // This software is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this software; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
22 // VNCProxySocket.java together with VNCProxySocketFactory.java
23 // implement an alternate way to connect to VNC servers via one or two
24 // VNCProxy proxies supporting the VNCProxy VNCCONNECT method.
30 class VNCProxyConnectSocketWrapper extends SocketWrapper {
32 public VNCProxyConnectSocketWrapper(Socket sock,
33 String vmname, String authtoken)
38 // Send the CONNECT request
39 getOutputStream().write(("CONNECTVNC " + vmname +
40 " VNCProxy/1.0\r\nAuth-token: " + authtoken +
41 "\r\n\r\n").getBytes());
43 // Read the first line of the response
44 DataInputStream is = new DataInputStream(getInputStream());
45 String str = is.readLine();
47 // Check the HTTP error code -- it should be "200" on success
48 if (!str.startsWith("VNCProxy/1.0 200 ")) {
49 if (str.startsWith("VNCProxy/1.0 "))
50 str = str.substring(13);
51 throw new IOException("Proxy reports \"" + str + "\"");
54 // Success -- skip remaining HTTP headers
57 } while (str.length() != 0);