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
  1. Allocate a stream socket with socket. Use AF_IRDA for the address format parameter and SOCK_STREAM for the type.
  2. Bind the service name to the socket with bind. Pass a SOCKADDR_IRDA structure for the address parameter.
  3. Listen for an incoming connection with listen.
  4. Accept an incoming client with accept.
  5. Use send and recv to communicate with the client.
  6. Close the socket with closesocket.
    To create and use a socket with a client application
  1. Allocate a stream socket with socket, as with the server application.
  2. Search for the server, and retrieve its ID with getsockopt.
  3. Connect to the server with connect, using SOCKADDR_IRDA for the name parameter.
  4. Use send and recv to communicate with the server.
  5. 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.