How to establish a GPRS connection in Windows Mobile so that the socket can communicate properly

Source: Internet
Author: User
Tags socket

A recent program to write a medical program, using Windows Mobile to do communications, requires that the data from the phone's end be sent over GPRS to a server on the public web. Data transfer I used the socket, with data line +activesync debugging through, normal data transmission, in preparation for the software to be submitted to the Quality Inspection department, with the real GPRS to do the communication test, the problem comes out, the connection is always built, but the mobile phone's IE browser can normally open the Web page, And strange is that as long as the use of IE browser successfully visited a Web page, my socket can be normal data communication, it seems that the legendary GPRS often connected by me misunderstood.

Mobile phone opened GPRS, our socket program can not directly establish a network connection, need to use Connection Manager to obtain the current available connections, and automatically select an optimal connection path, and then enable this connection, after the successful connection started with the socket for network connection can be normal. Probably GPRS dialing and connection process is here automatically. The source code encapsulates a connection-managed class and test code to see exactly what Windows Mobile needs to do before the socket is programmed.

You first need to enumerate the currently available connections

void CConnectManager::EnumNetIdentifier ( OUT CStringArray &StrAry )
{
  CONNMGR_DESTINATION_INFO networkDestInfo = {0};
  // 得到网络列表
  for ( DWORD dwEnumIndex=0; ; dwEnumIndex++ )
  {
    memset ( &networkDestInfo, 0, sizeof(CONNMGR_DESTINATION_INFO) );
    if ( ConnMgrEnumDestinations ( dwEnumIndex, &networkDestInfo ) == E_FAIL )
    {
      break;
    }
    StrAry.Add ( networkDestInfo.szDescription );
  }
}

Next, find the Internet connection, which can be done using remote URL mapping, which allows the system to automatically pick a best connection.

int CConnectManager::MapURLAndGUID ( LPCTSTR lpszURL, OUT GUID &guidNetworkObject, OUT CString *pcsDesc/*=NULL*/ )
{
  if ( !lpszURL || lstrlen(lpszURL) < 1 )
    return FALSE;
  memset ( &guidNetworkObject, 0, sizeof(GUID) );
  int nIndex = 0;
  HRESULT hResult = ConnMgrMapURL ( lpszURL, &guidNetworkObject, (DWORD*)&nIndex );
  if ( FAILED(hResult) )
  {
    nIndex = -1;
    DWORD dwLastError = GetLastError ();
    AfxMessageBox ( _T("Could not map a request to a network identifier") );
  }
  else
  {
    if ( pcsDesc )
    {
      CONNMGR_DESTINATION_INFO DestInfo = {0};
      if ( SUCCEEDED(ConnMgrEnumDestinations(nIndex, &DestInfo)) )
      {
        *pcsDesc = DestInfo.szDescription;
      }
    }
  }
  return nIndex;
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.