Added simple instruction forwarding client, added to session.

This commit is contained in:
Michael Jumper
2010-09-05 00:05:45 -07:00
parent 2523a39df6
commit 6e253d8680
2 changed files with 122 additions and 1 deletions

View File

@@ -0,0 +1,117 @@
package net.sourceforge.guacamole;
/*
* Guacamole - Clientless Remote Desktop
* Copyright (C) 2010 Michael Jumper
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
import java.io.InputStream;
import java.io.BufferedInputStream;
import java.io.Reader;
import java.io.InputStreamReader;
import net.sourceforge.guacamole.instruction.Instruction;
import net.sourceforge.guacamole.GuacamoleException;
import net.sourceforge.guacamole.event.KeyEvent;
import net.sourceforge.guacamole.event.PointerEvent;
public class GuacamoleClient extends Client {
private Socket sock;
private Reader input;
public GuacamoleClient(String hostname, int port) throws GuacamoleException {
try {
sock = new Socket(InetAddress.getByName(hostname), port);
input = new InputStreamReader(new BufferedInputStream(sock.getInputStream()));
}
catch (IOException e) {
throw new GuacamoleException(e);
}
}
public void send(KeyEvent event) throws GuacamoleException {
// STUB
}
public void send(PointerEvent event) throws GuacamoleException {
// STUB
}
public void setClipboard(String clipboard) throws GuacamoleException {
// STUB
}
public void disconnect() throws GuacamoleException {
try {
sock.close();
}
catch (IOException e) {
throw new GuacamoleException(e);
}
}
private StringBuilder instructionBuffer = new StringBuilder();
public Instruction nextInstruction(boolean blocking) throws GuacamoleException {
try {
// While we're blocking, or input is available
while (blocking || input.ready()) {
int readChar = input.read();
if (readChar == -1)
return null;
// Add to buffer
instructionBuffer.append((char) readChar);
// If end of instruction, return it.
if (readChar == ';') {
// Get instruction, reset buffer
final String instruction = instructionBuffer.toString();
instructionBuffer.setLength(0);
// Return instruction string wrapped in Instruction class
return new Instruction() {
public String toString() {
return instruction;
}
};
}
} // End read loop
}
catch (IOException e) {
throw new GuacamoleException(e);
}
return null;
}
}

View File

@@ -25,6 +25,7 @@ import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionBindingEvent;
import javax.servlet.http.HttpSessionBindingListener;
import net.sourceforge.guacamole.Client;
import net.sourceforge.guacamole.GuacamoleClient;
import net.sourceforge.guacamole.GuacamoleException;
import net.sourceforge.guacamole.instruction.Instruction;
import net.sourceforge.guacamole.event.KeyEvent;
@@ -105,7 +106,10 @@ public class GuacamoleSession {
client = new SessionClient(
null /* CLIENT GOES HERE */
new GuacamoleClient (
"localhost", // Temporarily hard coded
1234
)
);
session.setAttribute("CLIENT", client);