Chapter 1. Winsock

Flying through wormholes ain't like dusting crops, Farm Boy.

?John Crichton, Farscape

Welcome to the world of communications and network programming using a Pocket PC device. You probably already know that these devices can perform a wide variety of useful functions?from scheduling to playing MP3s. However, one of the Pocket PC's least utilized features has been its capability to communicate with other devices and consume available services on the Internet.

In the past, getting access to a network usually involved plugging a modem or network card into your device, which typically is not the most portable means of communications. Today, with the advent of wide area wireless networking (using some cellular connection) and home/office wireless (using 802.11b or Bluetooth), connectivity issues have become a thing of the past. From the workplace to the home to the cafe, the Internet is now available everywhere.

As with most technologies, network programming is comprised of a set of building blocks?one piece built on top of another, providing more specific functionality the closer you get to the application level. Windows Sockets (also called Winsock) is a network application programming interface (API) that simplifies access to the network services of various protocols on your Pocket PC device. On Windows CE, it specifically provides an interface to the Transmission Control Protocol/Internet Protocol (TCP/IP), the network protocol for communications over the Internet; and for infrared communication (IrDA, which is covered in Chapter 5). You can think of TCP/IP as what talks to your network hardware, and Winsock as what your application uses to talk to TCP/IP.

Although most of the core Internet "applications," such as the Web (Hypertext Transfer Protocol, HTTP), e-mail (Simple Mail Transfer Protocol, SMTP) and FTP (File Transfer Protocol) provide a simplified API using WinInet (see Chapter 2), APIs such as WinInet are all built on top of Winsock and TCP/IP. Therefore, it is important to understand how the underlying functionality works in order to build efficient and compelling network applications.