WinSock, IrDA and You!
by Evan Golub

The problem as I see it...

In embedded Visual Basic (eVB) the WinSock control allows you to specify whether you want to communicate via TCP/IP or IrDA. All of the documentation does indicate that if you select IrDA, that you will want to set the ServiceName rather than use ports. However, what I did not find described was the fact (as far as I've been able to gather) that you still need to specify the RemoteHost to which you want to connect. This would be fine if there was a standard hostname (or IP address) for all PocketPC devices, but there is not one.

I am currently developing with an HP Jornada (hostname: HP548) and a Compaq iPAQ (hostname: Pocket_PC). I was able to get them to send information across IR using WinSock controls by filling these hostnames in manually. However, with IR, you shouldn't need to do this (and it really makes the IR application very frustrative if you do). I did experiment (briefly) with trying to use 127.0.0.1 for the remote hostname (a longshot but worth trying I thought) to no avail.


My solution....

What I decided to do for my solution was to have the device that was starting the WinSock server beam it's hostname out directly over the IR port, and then listen for WinSock requests. Since the IR port can be accessed as a COM port, this can be done as long as you know which COM port is the IR port (because different devices use different COM numbers). You can use API calls to get the COM port number out of the registry, so this solution can be automated. I have created a simple project that has you manually walk through the steps of the server listening and sending out its info and the client looking for that info and then connecting.

My current protocol is to have the server beam out its hostname a few times and then wait for a connection. If no connection comes within a certain amount of time (still tinkering with that part) it beams its hostname out again and then waits for a WinSock connection again. It is worth noting that you will need to close the IR COM port before listening with your IrDA WinSock, and close the IrDA WinSock before accessing the IR COM port. I have created an example project that has this protocol implemented. It is not tested for things like deadlock and hasn't been optimized yet.

I am still developing this idea, but since I was able to find so little information out there about IrDA over WinSock, I thought I would post this page while still experimenting with ideas to help other programmers avoid some of the headaches that I encountered when I started looking for a way to do IrDA WinSock communications without using any outside APIs.

Additional Note: In PocketPC 2002, the device defaults to having the IR port being listened to by the system. If you try to open the IR port, you get an error message. If you want to use the technique described above, you will need to go to Settings from the Start Menu, go to to Connections Tab, click on Beam and turn off Receive all incoming beams and select discoverable mode.