Using Infrared Sockets
The basic procedure for using IrSock is similar to that for Winsock. Server applications and client applications have somewhat different procedures.
To create and use a socket with a server application
- Allocate a stream socket with socket. Use AF_IRDA for the address format parameter and SOCK_STREAM for the type.
- Bind the service name to the socket with bind. Pass a SOCKADDR_IRDA structure for the address parameter.
- Listen for an incoming connection with listen.
- Accept an incoming client with accept.
- Use send and recv to communicate with the client.
- Close the socket with closesocket.
To create and use a socket with a client application
- Allocate a stream socket with socket, as with the server application.
- Search for the server, and retrieve its ID with getsockopt.
- Connect to the server with connect, using SOCKADDR_IRDA for the name parameter.
- Use send and recv to communicate with the server.
- Close the socket with closesocket.
The code examples in the following two sections demonstrate these procedures, using IAS. You could run these samples on a pair of Handheld PCs (H/PCs) or Palm-size PCs, for example.