Wireless Communication in iPAQ Using Embedded Visual C++ 3.0

Environment: Embedded VC++ 3.0

Introduction

Many doubts exist regarding how to perform a wireless communication procedure between a wireless handheld client and a server (possibly a desktop) within a network. This article serves to remove any difficulties present in understanding the concept. Also, it aims to eliminate all sorts of confusion in establishing a communication procedure between two remote hosts.

A handheld can communicate with the server by means of a wireless card. In general, a wireless communication can be classified into the Independent Basic Service set (IBSS) or the Basic Service Set (BSS). The IBSS consists of those wireless networks wherein an Access point is provided which would help identify the remote clients. BSS is of the ad hoc nature, wherein no access points are provided. Let’s not get into the technical intricacies of this wireless set of services. We shall now move towards establishing a simple wireless communication procedure between a handheld running Windows CE 3.0 and a desktop running any Windows OS.

A typical wireless scenario can be explained by the following figure. This is a typical scenario of the IBSS system.

For the handheld to become an active member in the wireless network, it should have an expansion pack with a wireless LAN card installed. Several companies such as 3COM, Lucent, and so forth, provide many LAN cards.

The first and foremost step would be install the corresponding driver in the handheld for your card to function perfectly. You need to read the documentation that comes with the card for the type of driver to install. That would not be difficult for anyone because it is well documented.

Once the driver is installed, your handheld is now ready to operate on the Internet. The iPAQ can be assigned IP addresses using this wireless LAN card. Once the IP address is assigned, the iPAQ becomes visible in the network. Communication can take place between the handheld and the desktop in the same network.

The 802.11 AP serves as the Network Access point, which is connected to the Ethernet. It consists of the LAN access Server Driver. When a wireless device needs to have the services of a LOCAL LAN, it connects to that using the Access points.

In the case of this approach, the iPAQ connecting as a client first communicates with the Access point to query the IP address of the server and then establishes the socket communication with the server. The socket communication that is established is the TCP or the reliable data communication. The client and the server then can exchange data with the help of the established datagram socket.

For perfect TCP communication to take place, you need to have two types of sockets. One is referred to as the listening socket and other is the communicating socket. Of course, this can also be done in several other methods but the one I chose is to have two different sockets so that multiple clients can be accommodated easily.

A typical socket can be created on the client side as:

m_pSocket = new CChatSocket (CCeSocket::FOR_DATA);
if (!m_pSocket->Create())
{
  delete m_pSocket;
  m_pSocket = NULL;
  AfxMessageBox(CString("Socket Creation Failed"));
  return FALSE;
}


if(!m_pSocket->Connect(lpszAddress, 707))
{
  AfxMessageBox(CString(
       "Socket failed to connect to the remote host"));
  delete m_pSocket;
  m_pSocket = NULL;
  return FALSE;
}

On the server side, to accept this connection from the client, it has to be in listen mode. This can be implemented as follows:

  #if defined(_WIN32_WCE)
// Establish a socket to listen for incoming connections.
m_pSocket = new CListeningSocket(this,
                                 CCeSocket::FOR_LISTENING );
#else // _WIN32_WCE
    m_pSocket = new CListeningSocket(this);
#endif // _WIN32_WCE
  if (m_pSocket->Create( 707 ))
  {
    if (m_pSocket->Listen())
      {
        return TRUE;
      }
  }

The connection from the client socket can be accepted as:

if (m_pSocket->Accept(*m_pClientSocket))
{
  m_pClientSocket->Receive(szHost,25,0);
  m_WndProgressCtrl.StepIt();
  m_csHost=szHost;
}

After the mutual handshake between the client and the server, the communication can take place reliably and efficiently.

A sample project accompanies this article; it aims to provide a practical implementation of the wireless socket communication. Please download the entire attachment. You have to use Embedded Visual C++ to compile the project workspace ScreenPPC and Visual C++ to compile the ScreenDesktop project workspace.

Downloads

Download source – 155 Kb

More by Author

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Must Read