mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 13:17:41 +00:00
Added socket connect timeout
This commit is contained in:
@@ -28,10 +28,14 @@ import java.io.InputStreamReader;
|
||||
|
||||
import java.io.Writer;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketAddress;
|
||||
|
||||
|
||||
public class GuacamoleTCPClient extends GuacamoleClient {
|
||||
|
||||
private static final int SOCKET_TIMEOUT = 5000;
|
||||
|
||||
private Socket sock;
|
||||
private Reader input;
|
||||
private Writer output;
|
||||
@@ -39,9 +43,21 @@ public class GuacamoleTCPClient extends GuacamoleClient {
|
||||
public GuacamoleTCPClient(String hostname, int port) throws GuacamoleException {
|
||||
|
||||
try {
|
||||
sock = new Socket(InetAddress.getByName(hostname), port);
|
||||
|
||||
// Get address
|
||||
SocketAddress address = new InetSocketAddress(
|
||||
InetAddress.getByName(hostname),
|
||||
port
|
||||
);
|
||||
|
||||
// Connect with timeout
|
||||
sock = new Socket();
|
||||
sock.connect(address, SOCKET_TIMEOUT);
|
||||
|
||||
// On successful connect, retrieve I/O streams
|
||||
input = new InputStreamReader(sock.getInputStream());
|
||||
output = new OutputStreamWriter(sock.getOutputStream());
|
||||
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new GuacamoleException(e);
|
||||
|
Reference in New Issue
Block a user