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

  • Home
  • SEARCH
  • 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 6387745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:11:27+00:00 2026-05-25T03:11:27+00:00

Hello I can not understand a single moment. The following code in a simple

  • 0

Hello I can not understand a single moment. The following code in a simple application is fulfilled perfectly:

     /**
      *
      * @author AKhusnutdinov
      */
     public class JavaApplication12 {

         /**
          * @param args the command line arguments
          */
         public static void main(String[] args) {
             Date startDate = new Date();
             String hostname = "ihtik.lib.ru";
             int port = 80;

             Socket socket = null;
             BufferedReader reader = null;

             try {
                 socket = new Socket();
                 socket.setSoTimeout(30000);
                 socket.connect(new InetSocketAddress(hostname, port),
 30000);
                 String writer = "GET /2011.06.03_prislan.ihtiku/
 HTTP/1.1\r\n"
                         + "Host: " + hostname + "\r\n"
                         + "Accept: */*\r\n"
                         + "User-Agent: Java\r\n"
                         + "\r\n";

 socket.getOutputStream().write(writer.getBytes("UTF-8"));
                 socket.getOutputStream().flush();

                 reader = new BufferedReader(new
 InputStreamReader(socket.getInputStream()));
                 for (String line; (line = reader.readLine()) != null;)
 {
     //                if (line.isEmpty()) {
     //                    break; // Stop when headers are completed.
 We're not interested in all the HTML.
     //                }
                     System.out.println(line);
                 }
             } catch (Exception ex) {
             } finally {
                 if (reader != null) {
                     try {
                         reader.close();
                     } catch (IOException logOrIgnore) {
                     }
                 }

                 if (socket != null) {
                     try {
                         socket.close();
                     } catch (IOException logOrIgnore) {
                     }
                 }
             }

             Date endDate = new Date();
             System.out.println(endDate.getTime() -
 startDate.getTime());
         }
     }

But in a GUI application, which was created in NetBeans (Desktop application Java, Swing) does not handle the same code, but it gives an error:

 run: java.net.SocketTimeoutException: Connect timed out
     at
 java.net.SocksSocketImpl.readSocksReply(SocksSocketImpl.java:125)
     at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:459)
     at java.net.Socket.connect(Socket.java:579)
     at
 desktopapplication1.DesktopApplication1View.<init(DesktopApplication1View.java:46)
     at
 desktopapplication1.DesktopApplication1.startup(DesktopApplication1.java:19)
     at
 org.jdesktop.application.Application$1.run(Application.java:171)
     at
 java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
     at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:705)
     at java.awt.EventQueue.access$000(EventQueue.java:101)
     at java.awt.EventQueue$3.run(EventQueue.java:666)
     at java.awt.EventQueue$3.run(EventQueue.java:664)
     at java.security.AccessController.doPrivileged(Native Method)
     at
 java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
     at java.awt.EventQueue.dispatchEvent(EventQueue.java:675)
     at
 java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:211)
     at
 java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
     at
 java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117)
     at
 java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)
     at
 java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)
     at java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
 ПОСТРОЕНИЕ УСПЕШНО ЗАВЕРШЕНО (общее время: 39 секунд)

Part code GUI applications:

 DesktopApplication1View extends FrameView {

     public DesktopApplication1View(SingleFrameApplication app) {
         super(app);

         initComponents();

         Date startDate = new Date();
         String hostname = "ihtik.lib.ru";
         int portt = 80;

         Socket socket = null;
         BufferedReader reader = null;
         try {
             socket = new Socket();
             socket.setSoTimeout(30000);
             socket.connect(new InetSocketAddress(hostname, portt),
 30000);
             String writer = "GET /2011.06.03_prislan.ihtiku/
 HTTP/1.1\r\n"
                     + "Host: " + hostname + "\r\n"
                     + "Accept: */*\r\n"
                     + "User-Agent: Java\r\n"
                     + "\r\n";
             socket.getOutputStream().write(writer.getBytes("UTF-8"));
             socket.getOutputStream().flush();

             reader = new BufferedReader(new
 InputStreamReader(socket.getInputStream()));
             for (String line; (line = reader.readLine()) != null;) {
 //                if (line.isEmpty()) { //                    break;
 // Stop when headers are completed. We're not interested in all the
 HTML. //                }
                 System.out.println(line);
             }
             reader.close();
             socket.close();
         } catch (Exception ex) {
             ex.printStackTrace();
         }

         // status bar initialization - message timeout, idle icon and
 busy animation, etc
         ResourceMap resourceMap = getResourceMap();
         int messageTimeout =
 resourceMap.getInteger("StatusBar.messageTimeout");
         messageTimer = new Timer(messageTimeout, new ActionListener()
 {
             public void actionPerformed(ActionEvent e) {
                 statusMessageLabel.setText("");
             }
         });

Why an error?

  • 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-25T03:11:29+00:00Added an answer on May 25, 2026 at 3:11 am

    You are running your code on the EventQueue. See here for more informations on this.

    The code needs to be moved to a separate thread, just doing invokeLater() will still run the code on the event thread.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

foo\r\nbar.replace(/(foo).+/m, bar) Hello. I can not understand why this code does not replace foo
Can any one explain why the output of this code is only 'hello' and
Could anyone help me to understand following line of code: sol< ?=f((1<< n)-1,i,0)+abs(P[i])*price; I
Hello SharePoint developpers ! I can't deeply understand the difference between Query and ViewXml
I understand #div:hover:not(.class) works. However, how can I achieve a "hover" effect for a
Hello all I hope you can help me understand why getopt used an int
I am not able to compile the following code. I run it in a
Hello I have the following error by git-fsck, which cannot be cleaned by git-gc
Hello can anybody solve this please I'm creating the object in the action class
In cmd.exe, I can execute the command copy c:\hello.txt c:\hello2.txt and it worked fine.

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.