Socket Programming in QNX

This chapter covers the following topics:

Introduction

The Socket interface library has been implemented to operate across the QNX network. This means that TCP/IP application programs can run on any computer in the QNX network.

This chapter provides specific information about generating socket-based applications in QNX.

The QNX TCP/IP socket interface is a set of library functions and header files. All memory models of the socket interface library are provided. They're called socketx.lib, where x denotes the memory model. For a description of memory models, see the documentation for the cc utility.

These libraries are installed in the /usr/lib directory. For references to socket functions, see the TCP/IP Libraries chapter in this guide.

The header files are installed under the /usr/include directory.

Compiling & linking

To compile socket programs, use the cc utility.

You should link with the following command:

cc -l socket -l unix program_name

The -l socket (``el'') option causes the linker to automatically append the letter for the appropriate memory model before referencing the socket library.

Specifying -l unix causes the linker to include the UNIX compatibility library. This ensures that the appropriate historical (non-POSIX) UNIX functions are available.


Note: The linking order of the libraries is important. Be sure to specify the -l socket option before the -l unix option.

Running programs

Before a program can be executed, the Socket Manager (Socket) must be running somewhere in the QNX network.


Note: We also have scaled-down versions of the Socket Manager:
  • If you don't need NFS support, you can use Socklet, which uses less memory than Socket.
  • If you need only a single PPP interface, you can use Sockppp.

For more information about Socket, Socklet, and Sockppp, see the TCP/IP User's Guide.

If multiple Socket Managers are running on different nodes in your QNX network and you have reason to select a specific one, you may do so by typing either:

SOCK=node_ID command

Or

export SOCK=node_ID; command

where node_ID is the QNX node ID of the machine running the Socket Manager that you wish to attach to. If you use the second form, all subsequent commands will be affected. For more information, see the LAN Configuration chapter in the TCP/IP User's Guide.