Archived

This forum has been archived. Please start a new discussion on GitHub.

Connection problem.

Hi ,
How to know there is a connection between the client and the server?
try
{
   o_PCProx.GetPCData();//o_PCProx  is  XXXPrx o_PCProx
}
catch(Ice.ConnectFailedException)
{

}
if there is a exception ,I think there is not a connection between the client and the server.
I want to know is there another method .

Comments

  • No, not really. Either the request succeeds, or you get an exception. You could call ice_connection() on a proxy but, if no connection exists at that point, ice_connection() will attempt to establish one.

    Why do you want to know?

    Michi.
  • Hi,Michi.
    public AgentPcInfoData GetPCData()
    		{
    		    return GetPCData(__defaultContext());
    		}
    
    public AgentPcInfoData GetPCData(Ice.Context __context)
    		{
    		    int __cnt = 0;
    		    while(true)
    		    {
    			try
    			{
    			    __checkTwowayOnly("GetPCData");
    			    Ice._ObjectDel __delBase = __getDelegate();
    		  _PCManagerDel __del = (_PCManagerDel)__delBase;
    			    return __del.GetPCData(__context);
    			}
    			catch(IceInternal.NonRepeatable __ex)
    			{
    			    __rethrowException(__ex.get());
    			}
    			catch(Ice.LocalException __ex)
    			{
    			    __cnt = __handleException(__ex, __cnt);
    			}
    		    }
    		}
    
    

    because,I don't start the server, when I execute " Ice._ObjectDel __delBase = __getDelegate();"in function GetPCData(),two handles will be created and not released.Why do I know the handles to be created? I observe the Handle count in the Windows Task manager.
  • matthew
    matthew NL, Canada
    The handles are probably socket connections that will be cleaned up when the objects are garbage collected.

    Matthew
  • Hi,Matthew
    Can you be sure that the objects must be collected by GC in Windows service pragram.I hope you can try it.
  • I do a simple demo to prove I said

    Hi.
    I only do the client demo.because I want prove when the server don't start some objects don't be released.
    And this demo as a Windows service program is started.

    my config: win2000,vs2003,C#,
  • Hi,
    Do you try it ? Why do the objects be release ?Can I release them by myself?
    what shall I do?
  • If you require help quickly, please contact us at info@zeroc.com for a commercial support contract.
  • Hi,
    I send a Email to info@zeroc.com.I hope some help as soon as possible.
    Thanks.
  • matthew
    matthew NL, Canada
    I had a look at your demo, and the communicator is not destroyed. For each communicator you create you must destroy it with a call to communicator.destroy(). If you do not, you will leak resource handles, as you've described.
  • hi,
    If I destroy the communicator , the function ProcessStart() do be charged to this:
    public void ProcessStart()
    {
    			string [] args= new string [1];
    			args[0]="";
    			//int i=0;
    			testIPrx p1=null;
    	Ice.Communicator o_icecomm=null;//=Ice.Util.initialize(ref args);
    string sConnectstr = "172.16.166.166" + "PCManager:default -h " + "172.16.166.166" + " -p " + "10007";
    
    while(true)
    {
       try
         {
    	 o_icecomm=Ice.Util.initialize(ref args);
    	Ice.ObjectPrx obj = o_icecomm.stringToProxy(sConnectstr);
    	 p1= testIPrxHelper.uncheckedCast(obj);
    	System.Threading.Thread.Sleep(6000);
    
    	p1.GetAgentData();// try to connect	
    	o_icecomm.destroy();
       }
      catch(Ice.ConnectFailedException)
       {
    	o_icecomm.destroy();
    					System.Threading.Thread.Sleep(5000);
    
      }
    
      }
    }
    
    
    but ,it will leak resource handles all the same.
  • matthew
    matthew NL, Canada
    As I said the problem is that the objects are awaing garbage collection. If you force a GC to occur after you destroy the communicator you will see the handle count rapidly stabilizes.

    Call:

    System.GC.Collect()

    After the communicator is destroyed.

    Your code also isn't correct. If you create a communicator you MUST destroy it always.

    Something like this:
    public void ProcessStart()
    {
    			string [] args= new string [1];
    			args[0]="";
    			//int i=0;
    			testIPrx p1=null;
    	Ice.Communicator o_icecomm=null;//=Ice.Util.initialize(ref args);
    string sConnectstr = "172.16.166.166" + "PCManager:default -h " + "172.16.166.166" + " -p " + "10007";
    
    while(true)
    {
       o_icecomm=Ice.Util.initialize(ref args);
       try
       {
    	Ice.ObjectPrx obj = o_icecomm.stringToProxy(sConnectstr);
    	 p1= testIPrxHelper.uncheckedCast(obj);
    	System.Threading.Thread.Sleep(6000);
    
    	p1.GetAgentData();// try to connect	
        }
        catch(Ice.ConnectFailedException)
        {
          System.Threading.Thread.Sleep(5000);
        }
        finally
        {
          o_icecomm.destroy()
        }
        System.GC.Collect();
      }
    }
    

    Regards, Matthew
  • Hi,matthew
    I tested your method.The objects can be released.
    Thank you very much.