Created
October 10, 2018 10:05
-
-
Save uphy/373ebbcf5721ebb54eaabb27de9261e9 to your computer and use it in GitHub Desktop.
Artifically create connection timeout error
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.IOException; | |
import java.net.HttpURLConnection; | |
import java.net.SocketTimeoutException; | |
import java.net.URL; | |
public class Main { | |
public static void main(String[] args) throws IOException, InterruptedException { | |
URL url = new URL("http://10.255.255.1:8080"); | |
HttpURLConnection con = (HttpURLConnection) url.openConnection(); | |
con.setConnectTimeout(1000); | |
try { | |
con.connect(); | |
} catch (SocketTimeoutException ex) { | |
System.out.println("Connection timeout occured"); | |
} finally { | |
con.disconnect(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment