How close server socket without throwing exception to accepted socket

Hi,
In my project, we are closing the server by running a program which connects to server through socket.
Through socket, it asks server to destroy all the process and atlast server exist it connection by
System.exit(0);
Because of this, accepted socket throws a socket exception which clients don't want to see in their log file.
Is there any way to close the server in the accepted socket or to close without throwing exception.
Thanks & Regards,
Nasrin.N

All you have to do is close the ServerSocket then wait for all currently executing accepted-socket threads to exit. Closing the ServerSocket won't do anything to accepted sockets, but terminating the process early via System.exit() will, and this is what you want to avoid.

Similar Messages

  • Check read/write acces to a certain folder without throwing exceptions

    Hello
    Can somebody help me in finding a method for getting the read/write acces status to a certain location?
    I need to have a function wich return me true when I have acces to read inside a folder for instance.
    Thanks in advance, Ciprian LUPU

    It appears as if you are somehow attempting to retrieve access control for a folder on a website (http://www.schaeffler.com/brasov/DATA/SP-ISB-F/F) using the below line. Is that correct?
     I would recommend reading the
    TOS of that site before proceeding any further.
    schaeffler.com\brasov\DATA\SP-ISB-F\F
    I'm not certain the code you are attempting to use could possibly do that. I tried accessing that link using http and ftp from a browser but nothing was found or returned.
    It's more than likely you would have to use some sort of webrequest of ftp capability to attempt to get that information if that folder exists. And I would suppose an account would have to be logged onto or something in order to access that location as I
    can not do it with a webbrowser nor am I asked to logon to access that location.
    Are you certain that location exists on that website?
    This is the error I received attempting to access that location with the code you used.
    System.InvalidOperationException: Method failed with unexpected error code 3.
    at System.Security.AccessControl.NativeObjectSecurity.CreateInternal(ResourceType resourceType, Boolean isContainer, String name, SafeHandle handle, AccessControlSections includeSections, Boolean createByName, ExceptionFromErrorCode exceptionFromErrorCode, Object exceptionContext)
    at System.Security.AccessControl.NativeObjectSecurity..ctor(Boolean isContainer, ResourceType resourceType, String name, AccessControlSections includeSections, ExceptionFromErrorCode exceptionFromErrorCode, Object exceptionContext)
    at System.Security.AccessControl.FileSecurity..ctor(String fileName, AccessControlSections includeSections)
    at System.IO.FileInfo.GetAccessControl()
    at WindowsApplication1.Form1.CanReadFolder(String DirectoryName) in C:\Users\John\AppData\Local\Temporary Projects\WindowsApplication1\Form1.vb:line 20
    Method failed with unexpected error code 3.
    at System.Security.AccessControl.NativeObjectSecurity.CreateInternal(ResourceType resourceType, Boolean isContainer, String name, SafeHandle handle, AccessControlSections includeSections, Boolean createByName, ExceptionFromErrorCode exceptionFromErrorCode, Object exceptionContext)
    at System.Security.AccessControl.NativeObjectSecurity..ctor(Boolean isContainer, ResourceType resourceType, String name, AccessControlSections includeSections, ExceptionFromErrorCode exceptionFromErrorCode, Object exceptionContext)
    at System.Security.AccessControl.FileSecurity..ctor(String fileName, AccessControlSections includeSections)
    at System.IO.FileInfo.GetAccessControl()
    at WindowsApplication1.Form1.CanReadFolder(String DirectoryName) in C:\Users\John\AppData\Local\Temporary Projects\WindowsApplication1\Form1.vb:line 20
    La vida loca

  • How to get server data without reading from the socket stream?

    My socket client checks for server messages through
                while (isRunning) { //listen for server events
                    try {
                            Object o = readObject(socket); //wait for server message
                                tellListeners(socket, o);
                    } catch (Exception e) {
                        System.err.println("ERROR SocketClient: "+e);
                        e.printStackTrace();
                    try { sleep(1000); } catch (InterruptedException ie) { /* ignore */ }
                }//next client connectionwith readObject() being
        public Object readObject(Socket socket) throws ClassNotFoundException, IOException {
            Object result = null;
    System.out.println("readObject("+socket+") ...");
            if (socket != null && socket.isConnected()) {
    //            ObjectInputStream ois = new ObjectInputStream(socket.getInputStream());
                ObjectInputStream ois = new ObjectInputStream(new DataInputStream(socket.getInputStream()));
                try {
                    result = ois.readObject();
                } finally {
    //                socket.shutdownInput(); //closing of ois also closes socket!
        //            try { ois.close(); } catch (IOException ioe) { /* ignore */ }
            return result;
        }//readObject()Why does ois.readObject() block? I get problems with this as the main while loop (above) calls readObject() as it's the only way to get server messages. But if i want to implement a synchronous call in adition to this asynchronous architecture (call listeners), the readObject() call of the synchronous method comes to late as readObject() call of the main loop got called before and therefore also gets the result of the (later) synchronous call.
    I tried fideling around with some state variables, but that's ugly and probably not thread safe. I'm looking for another solution to check messages from the server without reading data from the stream. is this possible?

    A quick fix:
    - Add a response code at the beginning of each message returned from the server indicating if the message is a synchronous response or a callback (asynch);
    - Read all messages returned from the server in one thread and copy callback messages in a calback message queue and the synch responses in an synch responses queue;
    - Modify your synchronous invocation to retrieve the response from the responses queue instead from the socket. Read the callback messages from the corresponding queue instead from the socket.
    Also take a look at my website. I'm implementing an upgraded version of this idea.
    Catalin Merfu
    High Performance Java Networking
    http://www.accendia.com

  • Sockets: How can server detect that client is no longer connected?

    Hi,
    I really need help and advice with the following problem:
    I have a Client - Server socket program.
    The server listens on port 30000 using a server socket on one machine
    The client connects to localhost on port 20000, previously creating an ssh port forward connection using the Jsch package from www.jcraft.com with
    "session.setPortForwardingL(20000, addr, 30000);"
    Then the client sends Strings to the server using a PrintWriter.
    Both are connected to each other through the internet and the server uses a dynamic dns service.
    This all works well until the IP address of the Server changes, The client successfully reconnects to the server using the dynamic dns domain name, but the server keeps listening on the old socket from the previous connection, while opening a new one for the new client connection. The server doesn't seem to notice that Client has disconnected because of this IP address change.
    looks like the server is stuck inside the while loop. If i cut the connection manually on the client side, the server seems to notice that the client has disconnected, and jumps out of the while look (see code below)
    this is the code I'm using for the server:
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.net.Socket;
    import java.util.logging.Logger ;
    public class SocketHandler extends Thread {
        static Logger logger = Logger.getLogger("Server.SocketHandler");
        private Socket clientSocket = null;
        private BufferedReader in = null;
        private InputStreamReader inReader = null;
        public SocketHandler(Socket clientSocket) throws IOException {
            this.clientSocket = clientSocket;
            inReader = new InputStreamReader(clientSocket.getInputStream ());
            in = new BufferedReader(inReader);
        public void run() {
            try {
                String clientMessage = null;
                while ((clientMessage = in.readLine()) != null) {
                    logger.info("client says: " + clientMessage);
            } catch (IOException e) {
                logger.severe(e.getMessage());
                e.printStackTrace();
            } finally {
                try {
                    logger.info("closing client Socket: " + clientSocket);
                    clientSocket.close();
                    in.close();
                    ServerRunner.list.remove(clientSocket);
                    logger.info("currently "+ServerRunner.list.size()+" clients connected");
                } catch (IOException e) {
                    logger.severe (e.getMessage());
                    e.printStackTrace();
    }I've tried making the server create some artificial traffing by writing some byte every few seconds into the clients OutputStream. However I get no exceptions when the IP address changes. The server doesn't detect a disconnected socket connection.
    I'd really appreciate help and advice

    If a TCP/IP peer is shut down "uncleanly", the other end of the connection doesn't get the final end of connection packet, and read() will wait forever. close() sends the final packet, as will killing the peer process (the OS does the close()). But if the OS crashes or for some other reason can't send the final packet, the server never gets notification that the peer has gone away.
    Like you say, one way is timeout, if the protocol is such that there always is something coming in at regular intervals.
    The other way is a heartbeat. Write something to the other end periodically, just some kind of "hello, I'm here, ignore this message". The other end doesn't even have to answer. If the peer has gone away, TCP will retransmit your heartbeat message a few times. After about a minute it will give up, and mark the socket as broken. read() will then throw an IOException. You could send heartbeats from the client too, so that the client detects if the server computer dies.
    TCP/IP also has a TCP-level heartbeat; see Socket.setKeepAlive(). The heartbeat interval is about two hours, so it takes it a while to detect broken connections.

  • How to throw exception in run() method of Runnable?

    Hi, everyone:
    I want to know how to throw exception in run() method of interface Runnable. Since there is no throwable exception declared in run() method of interface Runnable in Java API specification.
    Thanks in advance,
    George

    Thanks, jfbriere.
    I must add though that if your run() methodis
    executed after a call to Thread.start(), then
    it is not a good choice to throw anyRuntimeException
    from the run() method.
    The reason is that the thrown exception won't be
    handled appropriately by a try-catch block.Why do you say that "the thrown exception won't be
    handled appropriately by a try-catch block"? Can you
    explain it in more detail?
    regards,
    George
    Because the other thread runs concurrently with and independently of the parent thread, there's no way you can write a try/catch that will handle the new thread's exception: try {
        myThread.start();
    catch (TheExceptionYouWantToThrowFromRun exc) {
        handle it
    do the next thing This won't work because the parent thread just continues on after myThread.start(). Start() doesn't throw the exception--run() does. And our parent thread here has lost touch with the child thread--it just moves on to "do the next thing."
    Now, you can do some exception handling with ThreadGroup and uncaughtException(), but make sure you understand why the above won't work, in case that was what you were planning to do.

  • How can I close a contract without PO??

    Hello everybody,
    I need some help. I'm working with SRM 50. My client doesn't need PO because he only wants manage the contracts. Does somebody know how I can close a contract without PO??
    Thanks
    Iván Moreno

    Hi Ivan,
    Not really sure to understand your requirement...
    You can manage contracts without creating a single PO...
    You can "hold" the contract or change the end date so that the contract will not be used.
    Kind regards,
    Yann

  • How to throw Exception in Thread.run() method

    I want to throw exception in Thread.run() method. How can I do that ?
    If I try to compile the Code given below, it does not allow me to compile :
    public class ThreadTest {
         public static void main(String[] args) {
         ThreadTest.DyingThread t = new DyingThread();
         t.start();
         static class DyingThread extends Thread {
         public void run() {
         try {
                   //some code that may throw some exception here
              } catch (Exception e) {
              throw e;//Want to throw(pass) exception to caller
    }

    (a) in JDK 1.4+, wrap your exception in RuntimeException:
    catch (Exception e)
    throw new RuntimeException(e);
    [this exception will be caught by ThreadGroup.uncaughtException() of this thread's parent thread group]
    In earlier JDKs, use your own wrapping unchecked exception class.
    (b) if you know what you are doing, you can make any Java method throw any exception using Thread.stop(Throwable) regardless of what it declares in its "throws" declaration.

  • How can I close a document without saving changes?

    I'm using Pages 4.3 with OS10.9.1.
    Before I upgraded to OS10.9.1, when I closed a document (Command W) it asked me first if I want to save the changes I'd made to the document. I had the option of saving or not saving.
    Sometimes I want to close a document without saving the changes, for example if I edit a text, then decide I prefer the unedited version.
    But now that I'm using OS10.9.1, when I close a document, it automatically saves any changes I've made.
    How can I get back to the original option of saving or not saving changes when I close a document? This option was available with the same version of Pages, when used with an earlier OS.
    I've searched the Pages Users Guide, but can't find any answer, or default settings. Pages Preferences doesn't seem to address this.
    I'm not using track changes, so I don't think that's the problem.
    Any solutions would be greatly appreciated!

    [Viking: I am using v4.3. ... See my orginal post.]
    But I found the solution, for anyone else who is having the same problem....
    Open your computer's System Preferences > General, and click the box "Ask to keep changes when closing documents."
    Now, when you close a document in Pages, a window will open giving you the option of saving changes or not.
    (I don't know whether this works in Pagesv.5., buty it works with v.4.3)

  • How do I manage open files in Server 2012 without resorting to 3rd party application?

    How do I manage open files in Server 2012 without resorting to 3rd party application?
    I cannot find the Mange open files in FSRM.
    Thanks

    Wouldn't it make sense to place it in the server manager / shares section?
    I mean, second to creating or finding a share, isn't this what most users would be after?
    For like 20 years we've been trained to right click to find stuff Microsoft is hiding, and right click don't do nothin' here.  You gotta go hunting under tools.   Or, forget the new half-baked interface with half of what you need and go old school,
    direct to Start - Computer..Right Click.. whoops... that doesn't exist anymore.....
    Drool.........drool.............Find that hiding, blinking start button in a RDP session, click start after three trys,  and TYPE IN "Computer Management" .  Right Click, Pin it to your desktop, pin it to the start screen, pin it to the taskbar, send
    it to OneNote, and upload it to skydrive  so you can find it again, then get back to what you were doing....to find the cottin' pickin open files and kick your users off so you can have your way with the server.

  • How to publish to RH Server 7 without RH

    The situation is that we have outsourced our help content
    creation to a remote professional writer. She uses RH to create the
    content. We have licensed RH Server 7, but we can't seem to find a
    way to publish her content to our server, using the server itself.
    Other products do not require purchasing the authoring tool
    in order to manage publishing. Does anyone know how we can publish
    without needing RH?

    What you want can be accomplished (if I understand
    correctly).
    Scenario - Publishing WebHelp Pro Manually:
    If hers is the only RH 7 client license, she could publish
    WebHelp Pro locally to her hard drive, just as she no doubt does
    now to do her own QA. The path will look something like this:
    C:\MyProjectFolder\!SSL!\WebHelp_Pro
    She would then zip up the WebHelp_Pro output folder and its
    contents (not the whole project) and send it to you or your
    RoboHelp Server administrator (as an email attachment or via FTP?).
    You can do the QA by reviewing it on your local hard drive, then
    send it to the web admin for placing on the live server. There is
    no need for you or the web administrator to have a RH 7 client
    license for this to work. The QA is done by simply viewing the
    output locally.
    When the administrator receives it, the WebHelp_Pro output
    folder should be renamed to whatever the project name is (e.g.,
    MyProject). The admin would then copy the folder to the path of the
    directory where RoboHelp Server projects are kept: Here is a
    typical physical path on the RH Server machine (substitute the
    number "24" for whatever your server number is)
    C:\Program Files\Adobe\RoboHelp Server
    7\Servers\24\Projects\MyProject
    Finally, the web administrator would use the RoboHelp Server
    Configuration Manager application (only the admin has this, not the
    author) and use the Refresh command so that the newly copied folder
    and contents will show up on the server. The project can then be
    viewed by the end user.
    So, this does not require any additional licenses for the RH
    7 client (other than the one she already has).
    (One more thing. You want to make sure she is using RH 7 and
    not a previous version.)
    Thanx
    John

  • How to close locked tab without closing firefox

    When firefox freezes how do I close offending tab without closing firefox

    Start Firefox in <u>[[Safe Mode|Safe Mode]]</u> to check if one of the extensions (Firefox/Tools > Add-ons > Extensions) or if hardware acceleration is causing the problem (switch to the DEFAULT theme: Firefox/Tools > Add-ons > Appearance).
    *Do NOT click the Reset button on the Safe Mode start window or otherwise make changes.
    *https://support.mozilla.org/kb/Safe+Mode
    *https://support.mozilla.org/kb/Troubleshooting+extensions+and+themes
    If it works in Safe Mode and in normal mode with all extensions (Tools > Add-ons > Extensions) disabled then try to find which extension is causing it by enabling one extension at a time until the problem reappears.
    Close and restart Firefox after each change via "Firefox > Exit" (Windows: Firefox/File > Exit; Mac: Firefox > Quit Firefox; Linux: Firefox/File > Quit)
    *If you have many extensions then first enable half of the extensions to test which half has the problem.
    *Continue to divide the bad half that still has the issue until you find which one is causing it.

  • How do I close down apps without deleting them?

    how do I close down apps without deleting them?

    If you want to completely exit the apps, then press the home button twice to access the multitasking bar.  Then press and hold on one of the apps, they should start wiggling, and a red minus sign should appear in the corner of every app.  Press the red minus sign and the app should disappear signifying that it has successfully been quit.

  • How to delete/drop all the tables from SQL Server Database without using Enterprise Manager?

    How to delete/drop all the tables from SQL Server Database without using Enterprise Manager?
    I tried using DROP Tables, Truncate Database, Delete and many more but it is not working.  I want to delete all tables using Query Analyzer, i.e. through SQL Query.
    Please help me out in this concern.
    Nishith Shah

    Informative thread indeed. Wish I saw it early enough. Managed to come up with the code below before I saw this thread.
    declare @TTName Table
    (TableSchemaTableName
    varchar
    (500),
    [status] int
    default 0);
    with AvailableTables
    (TableSchemaTableName)
    as
    (select
    QUOTENAME(TABLE_SCHEMA)
    +
    +
    QUOTENAME(TABLE_NAME)
    from
    INFORMATION_SCHEMA.TABLES)
    insert into @TTName
    (TableSchemaTableName)
    select *
    from AvailableTables
    declare @TableSchemaTableName varchar
    (500)
    declare @sqlstatement nvarchar
    (1000)
    while 1=1
    begin
    set @sqlstatement
    =
    'DROP TABLE '
    + @TableSchemaTableName
    exec
    sp_executeSQL
    @sqlstatement
    print
    'Dropped Table : '
    + @TableSchemaTableName
    update @TTName
    set [status]
    = 1
    where TableSchemaTableName
    = @TableSchemaTableName
    if
    (select
    count([Status])
    from @TTName
    where [Status]
    = 0)
    = 0
    break
    end

  • There aren't any 'x' on the tabs so that i can close them. how do u close individual tabs without restarting firefox?

    there aren't any "x's" on the tabs so that i can close them. how do u close individual tabs without restarting firefox?

    Why not just... put an X on it?

  • How to close video window without closing iTunes?

    I usually watch video podcasts on iTunes rather than on my iPod. But when the video finishes, how do I close that window without closing iTunes?

    Oops. I just discovered the little white circle with the x in it, that appears in the upper right corner of the video window when the cursor is moved inside the window.

Maybe you are looking for

  • Flex 3 need help with panels in dynamic tabs

    I am building an app where the user can add tabs as needed.  Each tab will have 4 panels inside it.  I can't get my for loop to build the panels.  It keeps erroring out. So question is  1) How do I create these with a loop and 2) I am wanting to put

  • MP3 Music does not work.

    I just upgraded to Adobe Premiere Elements 13 so that I could use music in .MP3 format.  But it still doesn't let me use this music.  Can you tell what I am doing wrong? I get a message that says "The importer reported a generic error"

  • Data incosistency

    Dear experts                    Our client implemented  sap in 2006 ECC 6 version and 2011 they want to implement   new profit center instead of old profit center  .I have discussed with  client  what they are saying  they have implemented  document

  • CRM 5.0 Security

    Hi Does anyone has document regarding CRM 5.0 security please mail me at <b><removed_by_moderator></b> I don't have SAP market place access so please don't forward me the link.If anyone has access please download and mail me the documents. Any other

  • Formatting A Percentage Field

    I am trying to format a text field to produce a percentage. Currently when I input 50 into the field, it produces 50.00% (rather than 50%).  I am using a javascript that another member recommended, but I would like to know how I can remove the 2 deci