Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 707013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:13:48+00:00 2026-05-14T04:13:48+00:00

I have created a sample java socket application. I used Socket s = new

  • 0

I have created a sample java socket application.
I used Socket s = new Socket(ip, port) Now it works fine. but when my internet connection is very slow that time after a long interval (even if sometimes after 2 minutes) i used to get SocketTimeOutException in that line. means it gives that error while creating socket. I want the exception should be handled properly means if internet connection is very slow then if that error occurs it happens very late now .
I want if this type of error occurs then it should be caught very fast means the error should not come at such a delay interval of time rather it should come immediately.

How to achieve this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T04:13:48+00:00Added an answer on May 14, 2026 at 4:13 am

    Decrease socket timeout like:

    sock.connect(new InetSocketAddress("www.google.com", 80), 500);
    

    where 500 is timeout in milliseconds.

    Here a snippet that uses Socket class:

     try { 
          InetAddress addr = InetAddress.getByName("www.google.com");
          int port = 80; SocketAddress sockaddr = new InetSocketAddress(addr, port);
          Socket sock = new Socket(); 
          int timeoutMs = 500; 
          sock.connect(sockaddr, timeoutMs); 
        } 
    catch (SocketTimeoutException  e) { System.out.println("Timeout reached!");}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I have created a sample java swing application Mac os. Now I want
I have a DataInputStream , created from a Socket in Java. The connection is
i am very new to j2me. i have created a sample program, but i
I have created a sample report with crystal report 10. Now, I wanna to
Hi I am using 64bit Fedora 10 linux. I have created a sample java
I have created a sample jsp file and a java class. i am calling
I have written a program in Java which creates a socket connection for a
I have created one GWT sample project for Web Application. I have also created
I have created Sample.java servlet, it is in src folder. and created HTML page
I have created a simple web-service using Java. i want to load jars related

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.