locked
ConnMgrEstablishConnectionSync is not good? RRS feed

  • Question

  • Hello,

    I'm trying to establish connection to the internet using the following code, but not sure that this code is good.
    I want to keep my connection for hours (it's a voip program), but the tcp sockets in my application are dropped every one hour or two. Although there is a disconnection, the device still has IP and still shows that it's connected to internet in the status bar on the top. I tried on lots of HTC devices (HD2, Pro2, Pro, etc...)

    Can somebody tell if there is something wrong in the code?

    Thanks,
    Emil.

    void Connect()
    {
    	CONNMGR_CONNECTIONINFO ConnectionInfo;
    	ZeroMemory (&ConnectionInfo, sizeof (ConnectionInfo));
    	ConnectionInfo.cbSize = sizeof (ConnectionInfo);
    
    	ConnectionInfo.dwParams = CONNMGR_PARAM_GUIDDESTNET; 
    	ConnectionInfo.dwFlags = CONNMGR_FLAG_PROXY_HTTP; 
    
    	ConnectionInfo.dwPriority = CONNMGR_PRIORITY_USERINTERACTIVE; 
    	ConnectionInfo.bExclusive = TRUE;
    	ConnectionInfo.guidDestNet = GetNetworkForURL (L"http://www.msn.com");
    
    	return ConnMgrEstablishConnectionSync (&ConnectionInfo, &m_hConnection, 30000, dwStatus);
    }
    
    void Disconnect()
    {
    	HRESULT hr = ConnMgrReleaseConnection(m_hConnection, TRUE);
    	m_hConnection = NULL;
    }
    
    
    GUID ConnectionsManager::GetNetworkForURL (LPCTSTR url)
    {
    	DWORD dwIndex = 0;
    	GUID rv;
    	if (!SUCCEEDED (ConnMgrMapURL (url, &rv, &dwIndex)))
    		rv = GUID_NULL;
    
    	return rv;
    }

    Monday, April 19, 2010 6:30 AM

All replies

  • Hi Emil,

    Sometimes it is disconnected, it still have an IP, this should be cache problem.

     

    Best regards,
    Guang-Ming Bian - MSFT


    Please remember to mark the replies as answers if they help and unmark them if they provide no help
    Friday, April 23, 2010 6:09 AM