Results 1 to 2 of 2
Like Tree2Likes
  • 2 Post By Potato

Thread: How to know when to close a socket?

  1. #1
    yuval2111 is offline Member
    Join Date
    Dec 2011
    Posts
    1
    Rep Power
    0

    Default How to know when to close a socket?

    Hi,
    I have a c++ application "A" that run a Java application "B".
    My problem is how B could know if A is shut down/terminated?

    B is open a new Socket -
    ServerSocket m_serverSocket = new ServerSocket(m_portNumber);
    Socket m_clientSocket = m_serverSocket.accept();

    How can I know in the Java side if the c++ application is down and I need also to shut down the Java application?
    Using "SetKeepAlive" will help me?

    Thanks

  2. #2
    Potato is offline Member
    Join Date
    Dec 2011
    Posts
    25
    Rep Power
    0

    Default Re: How to know when to close a socket?

    Keep Alive won't really help you, unless you don't mind it realizing that the application has been terminated an hour earlier (dependent on your OS actually...)

    The fastest way to find out if the connection is still open is to try writing to the socket. It will throw an exception if the connection is closed.
    Fubarable and clydedoris like this.

Similar Threads

  1. Socket Programming ERROR : Socket not connected
    By vishrut_n_shah in forum Networking
    Replies: 0
    Last Post: 11-04-2011, 09:32 AM
  2. How to close this thread? (Socket listener)
    By zardos in forum New To Java
    Replies: 5
    Last Post: 03-02-2011, 10:27 PM
  3. Replies: 1
    Last Post: 07-02-2010, 01:18 PM
  4. Replies: 13
    Last Post: 04-09-2010, 11:15 AM
  5. append response to the request from Socket and write to another socket
    By vaibhav_singh_vs@yahoo.co in forum Networking
    Replies: 3
    Last Post: 04-17-2009, 07:02 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •