diff --git a/guacamole/client/src/net/sourceforge/guacamole/GuacamoleClient.java b/guacamole/client/src/net/sourceforge/guacamole/GuacamoleClient.java new file mode 100644 index 000000000..4980ac5c2 --- /dev/null +++ b/guacamole/client/src/net/sourceforge/guacamole/GuacamoleClient.java @@ -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 . + */ + +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; + } + +} diff --git a/guacamole/client/src/net/sourceforge/guacamole/net/GuacamoleSession.java b/guacamole/client/src/net/sourceforge/guacamole/net/GuacamoleSession.java index 197b7358c..a76060590 100644 --- a/guacamole/client/src/net/sourceforge/guacamole/net/GuacamoleSession.java +++ b/guacamole/client/src/net/sourceforge/guacamole/net/GuacamoleSession.java @@ -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);