mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 05:07:41 +00:00
Experimental improvement to client.
This commit is contained in:
@@ -25,6 +25,8 @@ import java.net.Socket;
|
|||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.BufferedInputStream;
|
import java.io.BufferedInputStream;
|
||||||
|
import java.io.Reader;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
|
||||||
import net.sourceforge.guacamole.instruction.Instruction;
|
import net.sourceforge.guacamole.instruction.Instruction;
|
||||||
import net.sourceforge.guacamole.GuacamoleException;
|
import net.sourceforge.guacamole.GuacamoleException;
|
||||||
@@ -34,13 +36,13 @@ import net.sourceforge.guacamole.event.PointerEvent;
|
|||||||
public class GuacamoleClient extends Client {
|
public class GuacamoleClient extends Client {
|
||||||
|
|
||||||
private Socket sock;
|
private Socket sock;
|
||||||
private InputStream input;
|
private Reader input;
|
||||||
|
|
||||||
public GuacamoleClient(String hostname, int port) throws GuacamoleException {
|
public GuacamoleClient(String hostname, int port) throws GuacamoleException {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
sock = new Socket(InetAddress.getByName(hostname), port);
|
sock = new Socket(InetAddress.getByName(hostname), port);
|
||||||
input = new BufferedInputStream(sock.getInputStream());
|
input = new InputStreamReader(sock.getInputStream());
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (IOException e) {
|
||||||
throw new GuacamoleException(e);
|
throw new GuacamoleException(e);
|
||||||
@@ -69,39 +71,48 @@ public class GuacamoleClient extends Client {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private StringBuilder instructionBuffer = new StringBuilder();
|
private int bufferPos = 0;
|
||||||
|
private char[] buffer = new char[20000];
|
||||||
|
|
||||||
public Instruction nextInstruction(boolean blocking) throws GuacamoleException {
|
public Instruction nextInstruction(boolean blocking) throws GuacamoleException {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
// While we're blocking, or input is available
|
// While we're blocking, or input is available
|
||||||
while (blocking || input.available() > 0) {
|
while (blocking || input.ready()) {
|
||||||
|
|
||||||
int readChar = input.read();
|
int numRead = input.read(buffer, bufferPos, buffer.length - bufferPos);
|
||||||
if (readChar == -1)
|
if (numRead == -1)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
// Add to buffer
|
for (int i=bufferPos+numRead-1; i>=bufferPos; i--) {
|
||||||
instructionBuffer.append((char) readChar);
|
|
||||||
|
|
||||||
// If end of instruction, return it.
|
char readChar = buffer[i];
|
||||||
if (readChar == ';') {
|
|
||||||
|
|
||||||
// Get instruction, reset buffer
|
// If end of instruction, return it.
|
||||||
final String instruction = instructionBuffer.toString();
|
if (readChar == ';') {
|
||||||
instructionBuffer.setLength(0);
|
|
||||||
|
|
||||||
// Return instruction string wrapped in Instruction class
|
// Get instruction
|
||||||
return new Instruction() {
|
final String instruction = new String(buffer, 0, i+1);
|
||||||
|
|
||||||
public String toString() {
|
// Reset buffer
|
||||||
return instruction;
|
bufferPos = bufferPos + numRead - i - 1;
|
||||||
}
|
System.arraycopy(buffer, i+1, buffer, 0, bufferPos);
|
||||||
|
|
||||||
|
// Return instruction string wrapped in Instruction class
|
||||||
|
return new Instruction() {
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
return instruction;
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bufferPos += numRead;
|
||||||
|
|
||||||
} // End read loop
|
} // End read loop
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user