Creating an Infrared Winsock Application

The basic procedure for using IrSock is similar to that for Winsock. IrSock uses only the TCP stream socket connection-oriented communication method. Server applications and client applications have different procedures.

Note You must include the Af_irda.h header file in your application to access IrSock features in the Winsock functions.

    To create and use a socket with a server application

  1. Open a stream socket with socket. Use AF_IRDA for the address format parameter, SOCK_STREAM for the type and NULL for the protocol parameter.
  2. Bind the service name to the socket with bind. Pass a SOCKADDR_IRDA structure for the address parameter.
  3. Listen for an incoming client 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 the closesocket function.

For an example of an Infrared Sockets server application, see Infrared Sockets Server.

    To create and use a socket with a client application

  1. Open a stream socket with socket, as with the server application. Use AF_IRDA for the address format parameter, SOCK_STREAM for the type and NULL for the protocol parameter
  2. Search for the server, and retrieve its identifier with getsockopt.
  3. Connect to the server with the connect function using SOCKADDR_IRDA for the name parameter.
  4. Use send and recv to communicate with the server.
  5. Close the socket with closesocket.

For an example of an Infrared Sockets client application, see Infrared Sockets Client.