BLASTER – Winsock IrDA Sample Application

SUMMARY

Blaster is a simple application that illustrates Windows NT 5.0’s support of the IrDA protocol. IrDA provides reliable point to point connectivity between 2 computers equipped with infrared transceivers. Blaster uses the WinSock API with the IrDA address family to setup a single connection and "blast" random data to a peer machine that is also running blaster.

Blaster can be used during the development of Winsock application or OEM IrDA NDIS drivers to get an initial impression of performance.

BUILDING THE SAMPLE

To build BLASTER.EXE, select either the checked or free DDK environment, change to the directory BLASTER and type BUILD.

RUNNING THE SAMPLE

Copy BLASTER.EXE the test machine and run it.

RESOURCES

IrDA Winsock applications are discussed in greater detail in the .DOC files included in the IrDA section of the DDK samples.

CODE TOUR

File Manifest

Files         Description
BLASTER.HTM   The documentation for this sample (this file).
SOURCES       The generic file for building the code sample.
BLASTER.C     The Source for blaster.
BLASTER.RC    The resource file for blaster.
MAKEFILE      The standard DDK makefile.
RESOURCE.H    C Defines for blaster.
RESRC1.H      More C Defines.

Programming Tour

The major topics covered in this tour are:

The majority of code in this sample is actually devoted to window setup. The heart of the application and the source of most interest to the reader are the functions SendThread() and RecvThread(). All of the functionality required for IrDA connections are encapsulated there. The application itself is very simple. On startup, RecvThread() creates a socket to listen for incoming IrDA connections. When the user clicks the only button in the interface, SendThread() is invoked to enumerate available devices and establish a connection with the first visible device. It will proceed to ‘blast’ data through this connection, and then close it.

Enumerating Visible Devices

Infrared Devices which are in range will be enumerated when the user calls getsockopt() with the parameters of SOL_IRLMP and IRLMP_ENUMDEVICES. Note that no special coding is required if the computer has more than one IrDA adapter. The protocol will automatically query for all visible devices on all IrDA adapters present, and return them in a single call. Note that if a device is visible to more than one adapter, it may be presented twice in the list.

Bind()

Special notice is made here that, unlike other Winsock protocol families, no call to bind() is required before calling connect(). Bind() is normally used to insure the socket is correctly bound to a local address, generally for cases of multiple local adapters. The IrDA protocol abstracts multiple adapters so that this is not necessary. All context information needed to force the connection through the correct adapter is contained in the SOCKADDR_IRDA structure provided to connect(), in these fields: irdaDeviceID and irdaDeviceName. If you do attempt to bind() on an outbound connection, the connect() will return an error.