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 7610289
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:23:00+00:00 2026-05-31T01:23:00+00:00

I have a boolean variable to control the execution of the server (start/stop) :

  • 0

I have a boolean variable to control the execution of the server (start/stop) :

private boolean ecoute=true;

here is my class:

 sw=new SwingWorker<String,Void> (){

 protected String doInBackground() throws Exception {
    try {

            server = new ServerSocket(Integer.parseInt(port.getText()));

            String str1="waiting for connexion..";
            String str2="Connexion ok";

            log.append(str1+"\n");
            PrintWriter out=null;
            BufferedReader in=null;
            Socket socClient=null;
         while(ecoute){

                socClient = server.accept();  
                    log.append(str2+"\n");
                     in = new BufferedReader(
                                    new InputStreamReader(socClient.getInputStream())
                                   );
                   out = new PrintWriter(
                     new BufferedWriter(
                        new OutputStreamWriter(socClient.getOutputStream())), 
                     true);
                    String str = in.readLine();
                    log.append(str+"\n");

         }

            in.close();
            out.close();
            socClient.close();
            return "***End Reception***";
    } catch (IOException ex) {
        Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, ex);
        return "***Error Reception***";
    }

       }

       protected void done(){
       String m="";
            try {
                m=get();
            } catch (InterruptedException ex) {
                Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, ex);
            } catch (ExecutionException ex) {
                Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, ex);
            }
        log.append(m+"\n");

       }
    };
   sw.execute();
  }

when I click the button to pass the variable to false for my thread get out of the infinite loop,nothing happens :

 private void arretReceptionActionPerformed(java.awt.event.ActionEvent evt) {


    ecoute=false;

}

I replaced ecoute=false; by sw.calcel(true); also nothing new …

any suggestion ?

  • 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-31T01:23:01+00:00Added an answer on May 31, 2026 at 1:23 am

    Your ServerSocket is what’s causing the loop to not terminate. Even though ‘ecoute’ is false, server.accept() will block until one of the following two conditions is met:

    1. A connection is made to the ServerSocket
    2. The ServerSocket is closed.

    You need to do one of these two things so that the call to server.accept() will stop blocking. Mind you – if you choose to close the ServerSocket, an IOException will get thrown. It would probably be better to wrap the call to server.accept() in the try block, instead of wrapping the entire doInBackground() function.

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

Sidebar

Related Questions

I have a boolean variable declared at the top of a class and when
I have a boolean variable value stored in an SQL Server database. This is
I have a boolean variable and based on whether this is true or false
If you have a boolean variable: boolean myBool = true; I could get the
I have an SSIS package, which depending on a boolean variable, should either go
If I have a boolean field like: private static final boolean DEBUG = false;
I have a boolean variable that flags if a price (on an individual item)
I have a Boolean variable which I want to convert to a string: $res
AS3 newby here! I have a movieclip (thePlayer) on my stage with the class
I have a custom control MyControl . Has a parameterless constructor ( Sub New()

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.