Archived

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

one thread one session?

I make a funcation to create one session, and use it like this:

void main()
{
ClientUtil::GetInstance()->Open("192.168.1.2", 1212);
CreateThread( client ); // create the thread(client)
while(1) {};
}

DWORD WINAPI client( void* pParameter )
{
ClientUtil::GetInstance()->GetComputerInfo();
}

and in ClientUtil::GetComputerInfo() code like :

(1)slice::ComputerOperPrx ComputerProxy =
slice::ComputerInfoChangeOperPrx::checkedCast(refCommunicator->stringToProxy("Computer"));
(2)slice::ComputerPtr pComptuer =
ComputerProxy ->findComputerInfo( strComputerGuid );

when run this exe, ClientUtil::GetInstance()->GetComputerInfo() was faild,
fail code is (1) and ice Exception is Ice::NoEndpointException why:confused:

i try write ClientUtil::Open() and ClientUtil::GetComputerInfo() in a thread,the exe is sucess.

the clientutil::open() code:
HRESULT ClientUtil::Open( LPCTSTR strIPAddress, int nPort )
{
TCHAR szLocator[512] = { 0 };
sprintf( szLocator, "NetSecIceGrid/Locator:tcp -h %s -p %d",
strIPAddress, nPort );
try
{
m_Communicator->setDefaultLocator( Ice::LocatorPrx::uncheckedCast(
m_Communicator->stringToProxy(szLocator)));

slice::RouterDistributorOperPrx locatorPrx = NULL;
locatorPrx = slice::RouterDistributorOperPrx::uncheckedCast(
m_Communicator->stringToProxy("RouterDistributor"));

m_routerProxy =Glacier2::RouterPrx::uncheckedCast(
locatorPrx->ice_timeout(30000)->getDefaultRouter());
locatorPrx->ice_getConnection()->close(true);
m_Communicator->getDefaultLocator()->ice_getConnection()
->close(true);

m_Communicator->setDefaultLocator(NULL);
m_Communicator->setDefaultRouter(m_routerProxy);

m_Session = m_routerProxy->createSession("Agent","Agent");

}
catch (const Ice::Exception& ex)
{
printf("ice error is %s\n", ex.ice_name() );
}
return S_OK;
}