Exiting a server loop

hi guys,
does anyone know the correct way to exit a server loop, at the moment i have ....
while(!SrvInput.getEndProgStatus()){          
sk = skt.accept();
System.out.println("Accepting new client connection");
serverThread st = new serverThread(sk, conn);
st.start();
this just loops around creating a new thread for every client that connects, i have a class SrvInput which reads input from the console so if the user types "quit" the end prog status flag is set to true and the server exits.
the problem is that for it to exit i need one more person to connect since it blocks on the accept call.
Does anyone know how i can sort this out
thanks for any help

Hi.
I'm trying to solve the same problem. I solve it, sending myself a Socket conection and then existing the while code like this:
    public void run()
        while (!isFinish())
            try
                System.out.println("Waiting for connections.");
                Socket client = serverSocket.accept();
                if (!isFinish())
                    System.out.println("Accepted a connection from: "+client.getInetAddress());
                    LocationThread connect = new LocationThread(client);
            }catch(Exception e)
                System.out.println(e.getMessage());
                e.printStackTrace();
        try
            System.out.println("Server exiting");
            join(); // remove  join(), this a test.....
            serverSocket.close();
            System.out.println("Server has exit");
        }catch(Exception e)
            System.out.println("Error al cerrar el Socket");
    }This code belongs to the server side.
I do this, in a Button in a GUI interface.
        try{
            location.setFinish(true);
            Socket s = new Socket(InetAddress.getLocalHost(),Integer.parseInt(result));
        }catch(Exception e)
            System.out.println("Error al tratar de terminar el servidor");
        }But I have a problem, I want my server to wait for their childs to finish, How can I do it?.
a Join() , do the server to hang.
Any suggestion ?.

Similar Messages

  • ReadUTF() and exiting a server while loop

    What I want to do is simple.. I want to be able to type "exit" into a client and send that message to the server... And exit the server while loop as a result.. Here is what I tried.
    //server code
    while(true)
    //bla bla bla
    //bla bla bla
    String message = socket.readUTF();
    if( message == "exit" )
    break;
    // bla bla bla
    however, when I type exit and send the message, this while loop doesn't break.. I'm new to java so I'm wondering if I'm messing up syntax somewhere.. It seems like it should work fine, whats going on?

    if(message.equals("exit"))

  • Which system variable is reset at the exit of a loop of an internal table

    which system variable is reset at the exit of a loop of an internal table
    a)sy-loop b)sy-index c)sy-dbcnt d)sy-tabix

    You might want to revist your threads from Friday, and award points and mark as "Answered" or "Solved".
    Regards,
    Rich Heilman

  • How to terminate or exit a for loop when the user clicks on stop button

    Actually my problem is to stop a loop when i click on stop button.
    example:i have two buttons 'start' and 'stop'
    in start buttom i wrote a for loop as
    dim i as integer
    For i=1 To 100000
    print i
    Next
    when i click on start buuton it prints 'i' value up tp 100000.
    my question is when i click on 'Stop' button the for loop has to terminate or Exit from the  loop and should stops the execution.
    Is it possible to termianate or Exit the 'for loop'
    PS.Shakeer Hussain
    Hyderabad

    I am unable to stop the loop and application not at all allowing to Press the Stop button.
    It seems like Hung, any advise ?
    Private Sub btnStart_Click(sender As Object, e As EventArgs) Handles btnStart.Click
            btnStop.Enabled = True
            btnSelectFile.Enabled = False
            btnStart.Enabled = False
            btnStop.Focus()
            Dim strFileName As String = txtFileName.Text.ToString
            Dim strLineText As String
            If System.IO.File.Exists(strFileName) = True Then
                Dim objReader As New System.IO.StreamReader(strFileName)
                While objReader.Peek() <> -1 And stopclick = False
                    strLineText = objReader.ReadLine()
                    MsgBox(strLineText, MsgBoxStyle.Information)
                    Application.DoEvents()
                    Thread.Sleep(My.Settings("strDelay") * 1000)
                    'System.Diagnostics.Process.Start(My.Settings("strFireFoxLocation"), strLineText)
                End While
            End If
        End Sub
        Private Sub btnStop_Click(sender As Object, e As EventArgs) Handles btnStop.Click
            stopclick = True
            btnSelectFile.Enabled = True
            btnStart.Enabled = True
            btnStop.Enabled = False
        End Sub
    Raman Katwal
    Please remember to mark the replies as answers if they help and unmark them if they provide no help

  • How to exit from a loop on 2 different conditions

    Hello Experts
    I’m trying to write a procedure in which I’m taking PROVINCE as an input parameter. All the provinces are stores in a table. I’m using a cursor and rowtype variable to check the province. After I finds province I displays province and its code. Everything works fine expect when I don’t find the province. I’m not sure how to exit from loop if I don’t find the province. I already uses exit when condition. I was expecting else condition should work and should exit from the loop but it doesn’t. Can please somebody show me how to exit if I don’t find province in the table through cursor.
    Here is my code
    set serveroutput on
    variable G_TAX varchar2(10)
    CREATE OR REPLACE PROCEDURE p_create(i_state VARCHAR2)is
    CURSOR cur_bb_tax is
    select * from bb_tax;
    bb_tax_details bb_tax%rowtype;
    begin
    if not cur_bb_tax%isopen then
    open cur_bb_tax;
    end if;
    loop
    fetch cur_bb_tax into bb_tax_details;
    if (bb_tax_details.state = i_state) then
    dbms_output.put_line(bb_tax_details.state || bb_tax_details.idstate);
    end if;
    exit when bb_tax_details.state = i_state;
    end loop;
    close cur_bb_tax;
    exception
    when others then
    dbms_output.put_line(SQLERRM);
    end;
    Thanks in advance

    Hello,
    Why don't you use dbms_output.Put_line and print output to find why logic is not able to execute? Maybe upper case/lower case/whitespace. *Also put your code between \ to preserve formatting*.
    Regards                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • How to EXIT the while loop in Event response section?

    I'm writing a program to grab image using a NI card. The application uses the Event structure. When the GRAB button was pressed, it snaps image continually by putting the SNAP function in a while loop. Is there some way to exit the while loop?(Note :The while loop was put in the GRAB IMAGE event response section.)

    edit this event-case AND uncheck "lock front panel until the event case for this event completes".
    BTW, your thanks should go to Ankita, <a href='http://forums.ni.com/ni/board/message?board.id=170&message.id=151282'>here</a>
    cheers! 
    Message Edited by Dynamik on 11-13-2005 01:26 AM
    Message Edited by Dynamik on 11-13-2005 01:38 AM
    When they give imbeciles handicap-parking, I won't have so far to walk!
    Attachments:
    untitled.GIF ‏20 KB

  • Stopping output tasks properly before exiting a For-loop

    Hi,
    I've been having some trouble exiting a For-loop conditionally. The problem is that when the loop is stopped conditionally (a button is pressed) the DAQ (NI USB 6353) outputs get stuck to whatever value they were in. I tried stopping the DAQ Assistant output task (1 sample on demand)  before exiting the loop but that didn't solve the problem. Should this perhaps be done one iteration before exiting the loop or can it be done in the same iteration round?
    What would be the "right" way to exit a for loop with output tasks so that the output signals would be 0V after exiting? I know that I could "force" feed the DAQ Assistant with 0V control before exiting but in this case that would be quite difficult...
    Any ideas? Help is appriciated.

    Yes, I get it... However at this point I don't think that's an option.
    Would this kind of solution work? ( I am not able to test all possible solutions in the real system which is why I would like to get a confirmation first)
    The idea is to connect the output of the "Or" port to the "Stop" -ports of the DAQ Assistants in the loop.
    Edit. Will the output automatically go to 0V if I just stop the task? I am not really sure about this.
    Thank you.
    Attachments:
    exit-loop.jpg ‏8 KB

  • How to exit from the loop

    loop at itab.
    if <CONDITION>
    <EXIT LOOP>
    endif
    endloop.
    this ths condition , pz tel how to exit from loop

    Hi
    Loop
       statements
    EXIT
    Endloop.
    Will comes out of the loop.
    Regards,
    Sreeram Kumar.Madisetty

  • Dr. Watson Error on exiting weblogic server 6.1

    Hi,
    I sometimes get the Dr.watson error when I stop my weblogic server.
    The details are given below.
    I have weblogic 6.1
    Windows 2000 5.00.2195 Service pack 2
    Memory=392mb
    The message from Dr. Watson is:-
    "Dr. watson was unable to attach to the process. It is possible that process exited
    before Dr. Watson could attach to it.
    Windows 2000 error code=87 The parameter is incorrect."
    The message from the console is:-
    <Jan 15, 2002 5:08:10 PM CST> <Critical> <Kernel> <Execute Thread: 'ExecuteThread:
    '9' for queue: 'default'' stopped.>
    <Jan 15, 2002 5:08:10 PM CST> <Critical> <Kernel> <Execute Thread: 'ExecuteThread:
    '0' for queue: 'default'' stopped.>
    <Jan 15, 2002 5:08:11 PM CST> <Critical> <Kernel> <Execute Thread: 'ExecuteThread:
    '1' for queue: 'default'' stopped.>
    <Jan 15, 2002 5:08:11 PM CST> <Critical> <Kernel> <Execute Thread: 'ExecuteThread:
    '2' for queue: 'default'' stopped.>
    <Jan 15, 2002 5:08:11 PM CST> <Critical> <Kernel> <Execute Thread: 'ExecuteThread:
    '3' for queue: 'default'' stopped.>
    <Jan 15, 2002 5:08:12 PM CST> <Critical> <Kernel> <Execute Thread: 'ExecuteThread:
    '4' for queue: 'default'' stopped.>
    <Jan 15, 2002 5:08:12 PM CST> <Critical> <Kernel> <Execute Thread: 'ExecuteThread:
    '5' for queue: 'default'' stopped.>
    <Jan 15, 2002 5:08:12 PM CST> <Critical> <Kernel> <Execute Thread: 'ExecuteThread:
    '6' for queue: 'default'' stopped.>
    <Jan 15, 2002 5:08:12 PM CST> <Critical> <Kernel> <Execute Thread: 'ExecuteThread:
    '7' for queue: 'default'' stopped.>
    <Jan 15, 2002 5:08:13 PM CST> <Critical> <Kernel> <Execute Thread: 'ExecuteThread:
    '8' for queue: 'default'' stopped.>
    <Jan 15, 2002 5:08:13 PM CST> <Critical> <Kernel> <Execute Thread: 'ExecuteThread:
    '10' for queue: 'default'' stopped.>
    <Jan 15, 2002 5:08:13 PM CST> <Critical> <Kernel> <Execute Thread: 'ExecuteThread:
    '11' for queue: 'default'' stopped.>
    <Jan 15, 2002 5:08:13 PM CST> <Critical> <Kernel> <Execute Thread: 'ExecuteThread:
    '14' for queue: 'default'' stopped.>
    <Jan 15, 2002 5:08:13 PM CST> <Critical> <Kernel> <Execute Thread: 'ExecuteThread:
    '0' for queue: '__weblogic_admin_html_queue'' stopped.>
    <Jan 15, 2002 5:08:13 PM CST> <Critical> <Kernel> <Execute Thread: 'ExecuteThread:
    '1' for queue: '__weblogic_admin_html_queue'' stopped.>
    <Jan 15, 2002 5:08:13 PM CST> <Critical> <Kernel> <Execute Thread: 'ExecuteThread:
    '0' for queue: '__weblogic_admin_rmi_queue'' stopped.>
    <Jan 15, 2002 5:08:13 PM CST> <Critical> <Kernel> <Execute Thread: 'ExecuteThread:
    '1' for queue: '__weblogic_admin_rmi_queue'' stopped.>
    <Jan 15, 2002 5:08:14 PM CST> <Critical> <Kernel> <Execute Thread: 'ExecuteThread:
    '2' for queue: '__weblogic_admin_rmi_queue'' stopped.>
    <Jan 15, 2002 5:08:14 PM CST> <Critical> <Kernel> <Execute Thread: 'ExecuteThread:
    '3' for queue: '__weblogic_admin_rmi_queue'' stopped.>
    <Jan 15, 2002 5:08:14 PM CST> <Critical> <Kernel> <Execute Thread: 'ExecuteThread:
    '4' for queue: '__weblogic_admin_rmi_queue'' stopped.>
    <Jan 15, 2002 5:08:14 PM CST> <Critical> <Kernel> <Execute Thread: 'ExecuteThread:
    '5' for queue: '__weblogic_admin_rmi_queue'' stopped.>
    <Jan 15, 2002 5:08:14 PM CST> <Critical> <Kernel> <Execute Thread: 'ExecuteThread:
    '6' for queue: '__weblogic_admin_rmi_queue'' stopped.>
    <Jan 15, 2002 5:08:14 PM CST> <Critical> <Kernel> <Execute Thread: 'ExecuteThread:
    '7' for queue: '__weblogic_admin_rmi_queue'' stopped.>
    C:\bea\wlserver6.1>goto finish
    C:\bea\wlserver6.1>cd config\mydomain
    C:\bea\wlserver6.1\config\mydomain>ENDLOCAL
    C:\bea\wlserver6.1\config\mydomain>

    I talked with Sun today about this issue and they stated that the error I received is the result of a bug. Sun Bug ID: 6650667
    Synopsis: Cannot repack the changelog after trimming. libdb: DB_ENV->log_put: record larger than maximum file
    We can see the the following lines in your error log:
    [05/Jan/2010:00:05:03 -0500] - DEBUG - conn=-1 op=-1 msgId=-1 - libdb: DB_ENV->log_put: record larger than maximum file size (15956384 > 10485760)
    [05/Jan/2010:00:05:03 -0500] - Repacking backend 'changelog', LDAP entries error Invalid argument (22).
    [05/Jan/2010:00:05:03 -0500] - Repacking backend 'changelog' ended.
    There is no fix, and a workaround is listed as follows:
    Work Around:
    Increase nsslapd-db-logfile-size in dse.ldif (In entry "cn=config,cn=ldbm database,cn=plugins,cn=config" )
    This attribute is not present by default in the file.
    Its default value is 10485760.
    Which would make it the default as stated in the bug workaround.
    Make the change as directed above, perform the repack again and let me know the results.

  • Exit while in loop

    hie guys
    i am looping at two internal tables and want to exit through an if statement when a condition specified is not met however the code exits both loops.
    loop at itab1.
    loop at itab2.
    if itab2-value eq 0.
    exit.
    else.
    process.
    endif.
    endloop.
    endloop.
    however its not behaving as such..i have tryed to use return statement but it still wont work. i have verified my entries and the conditions exist to be true for some entries ie itab2-value ne 0 but the program exists. please assist.
    regards.
    Isaac Prince

    YOU CAN USE IT
    BUT THE SECOND TABLA MUS BE SORTED
    LOOP AT T_DOCTOS_WORK.
        T_DOCTOS_FINAL-BELNR_PAGO = T_DOCTOS_WORK-BELNR.
        T_DOCTOS_FINAL-BUDAT_CONCILIA = T_DOCTOS_WORK-AUGDT.
        T_DOCTOS_FINAL-BUDAT_PAGO = T_DOCTOS_WORK-BUDAT.
    Se tratan las partidad del proveedor
        READ TABLE T_DOC_BSIK_BSAK WITH KEY
            AUGGJ = T_DOCTOS_WORK-GJAHR
            AUGBL = T_DOCTOS_WORK-BELNR
            BINARY SEARCH.
        IF SY-SUBRC EQ 0.
          INDEXK = SY-TABIX.
          DO .
            READ TABLE T_DOC_BSIK_BSAK  INDEX INDEXK.
            IF T_DOC_BSIK_BSAK-AUGGJ NE T_DOCTOS_WORK-GJAHR OR
               T_DOC_BSIK_BSAK-AUGBL NE T_DOCTOS_WORK-BELNR OR
                SY-SUBRC NE 0.
              EXIT.
            ELSE.
              INDEXK = INDEXK + 1.
    *MAKE YOUR CODE
    ENDIF.
    ENDDO.
    ENDIF.
    ENDLOOP

  • EXIT STATMENT IN LOOP

    i want loop exit when there is no record
    loop
    select * from emp;
    exit when %norecordfound;
    end loop;
    wut's wrong with this exit statment

    Change your code. Since it is Pl/sql code, you can't write with out INTO clause.
    So u can use either CURSOR or SELECT INTO statement. Remember the SELECT into should return single value each time in the loop.
    DECLARE
    V1 table.c1%type;
    BEGIN
    loop
    SELECT c1 into V1 from TABLE;
    EXIT WHEN SQL%NOTFOUND;
    end loop;
    Cursor attribute %NOTFOUND can be used with Cursor name you have declared for the same purpose
    Cheers
    Ram
    Message was edited by:
    user504044

  • Exit condition in loop

    I am putting exit condition in before and after my business logic, so it make any difference
    BEGIN
         FOR REC IN 1..10
         LOOP
              EXIT WHEN REC =5;
              business logic
         END LOOP;
    END;
    BEGIN
         FOR REC IN 1..10
         LOOP
              business logic
              EXIT WHEN REC =5;
         END LOOP;
    END;Thanks
    Edited by: Braam on Oct 11, 2012 10:24 PM

    Would have been quicker for you to test it yourself, than to post the question:
    SQL> ed
    Wrote file afiedt.buf
      1  BEGIN
      2     FOR REC IN 1..10
      3     LOOP
      4             EXIT WHEN REC =5;
      5             /*
      6             business logic
      7             */
      8                  dbms_output.put_line('Processing: '||rec);
      9     END LOOP;
    10* END;
    11  /
    Processing: 1
    Processing: 2
    Processing: 3
    Processing: 4
    PL/SQL procedure successfully completed.
    SQL> ed
    Wrote file afiedt.buf
      1  BEGIN
      2     FOR REC IN 1..10
      3     LOOP
      4             /*
      5             business logic
      6             */
      7                  dbms_output.put_line('Processing: '||rec);
      8             EXIT WHEN REC =5;
      9     END LOOP;
    10* END;
    SQL> /
    Processing: 1
    Processing: 2
    Processing: 3
    Processing: 4
    Processing: 5
    PL/SQL procedure successfully completed.

  • Help -- How do I exit a Foreach Loop

    I have a foreach loop that is processing files in a directory.  One of the tasks is the execute sql task that calls a stored proc.  If this stored proc returns a certain value then I need to exit the loop and not process any more files.  But I have been unable to figure out how to make this happen.
    Any help would be greatly appreciated.
    Thanks!
    GN

     GN wrote:
    I have a foreach loop that is processing files in a directory. One of the tasks is the execute sql task that calls a stored proc. If this stored proc returns a certain value then I need to exit the loop and not process any more files. But I have been unable to figure out how to make this happen.
    Any help would be greatly appreciated.
    Thanks!
    GN
    have you considered using the script task instead?

  • Exit For Each Loop Container

    Is there a way in a foreach loop container to exit if the foreach loop container has been executing for a certain amount of time?
    Thanks.

    Hi miguelh,
    Based on my research, there is no such a property for Foreach Loop Container to achieve this requirement. Because the Foreach Loop Container itself execute the times based on the files loop.
    After testing the issue in my environment, we can add a Script Task inside the top of Foreach Loop Container to count the execute times, then add a precedence constraint with the count times on your tasks to limit the execute times. For more details, please
    see:
    Add a variable named Count in the package.
    Drag a Script Task inside the top of Foreach Loop Container.
    Double-click the Script Task, change ScriptLanguage to Microsoft Visual Basic 2010, then add User::Count as ReadOnlyVariables.
    Click Edit Script to add the code like below:
     Public Sub Main()
            ' Add your code here
            Dts.Variables("User::Count").Value = Dts.Variables("User::Count").Value + 1
            Dts.TaskResult = ScriptResults.Success
        End Sub
    Add a precedence constraint with Constraint options below:
    The following screenshot is for your reference:
    Thanks,
    Katherine Xiong
    If you have any feedback on our support, please click
    here.
    Katherine Xiong
    TechNet Community Support

  • Exiting from Inner Loop.

    Example.
    Loop at I_catsdb.
    Loop at I_catsdb_tmp.
    endloop.
    endloop.
    How do I come out of the inner loop on certain conditions?

    Hi,
    Use the EXIT statement..
    Loop at I_catsdb.
    Loop at I_catsdb_tmp.
    Check the conditions..
      EXIT. 
    endloop.
    endloop.
    Thanks,
    Naren

Maybe you are looking for

  • Not Receiving Fax's

    My HP Photosmart Premium Fax e-All-in-One Printer - C410a is not receiving any fax's!! Help please! All fax tests came as PASS when running the test on the printer.  All troubleshooting was done but with no success.  What can be the issue?? 

  • Safari 6.0.5 keeps crashing!!!

    I have Safari 6.0.5 (OS X 10.8.4) and it constantly crashes everytime I open it up.  It stays open for less than 3 seconds .  Does anyone have any tips?  I've some of the things such as removing plugins that may not be compatible, but still no luck. 

  • Help with non-Creative Travel Adap

    I have a Zen Plus V 8gb player. I bought a Hammacher Schlemmer travel adapter/converter (00v-240v) with USB port for an upcoming trip around the world. I plugged the USB cable into the mp3 player, however the little battery wasn't indicating that cha

  • Assign ECCN to Product in GTS

    Hello Experts, We want to mass upload ECCN assignment to Products which is manually done by transaction /SAPSLL/PR_PRCON_02. Is there and FM or BAPI available to assign ECCN and Flag for No Control to products. We have Logical System Group, Product N

  • Need to Allow Certain Third-Party Applications via MDM

    I just deployed a computer lab of iMacs and Minis and am using Yosemite/Server 4 to manage them. All computers are running 10.10.1 I Profile Manager>Restrictions, I want to allow users to use many native OS X applications but additionally I need to a