Skip to content

Commit 81f5e77

Browse files
Faster socket connection timeouts in RequestProgram (#9)
* Faster socket connection timeouts in RequestProgram Co-authored-by: Felix Exner <[email protected]>
1 parent b3eb873 commit 81f5e77

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/main/java/com/fzi/externalcontrol/impl/RequestProgram.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import java.io.DataOutputStream;
3030
import java.io.IOException;
3131
import java.io.InputStreamReader;
32+
import java.net.InetSocketAddress;
3233
import java.net.Socket;
3334

3435
public class RequestProgram {
@@ -50,7 +51,12 @@ public String sendCommand(String command) {
5051
String result = "";
5152
try {
5253
// socket creation
53-
Socket socket = new Socket(hostIp, portNr);
54+
Socket socket = new Socket();
55+
56+
// 5 second timeout (make configurable?)
57+
int timeout = 5*1000;
58+
socket.connect(new InetSocketAddress(this.hostIp, this.portNr), timeout);
59+
5460
if (socket.isConnected()) {
5561
// output stream creation
5662
DataOutputStream out = new DataOutputStream(socket.getOutputStream());

0 commit comments

Comments
 (0)