[Previous] [Contents] [Index] [Next]

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 of the cc utility in the C Library Reference.

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 (Tcpip) must be running somewhere in the QNX network. For more information about Tcpip, see the TCP/IP User's Guide.

If you have multiple Socket Managers running on different nodes in your QNX network, you can select a specific one by typing either:

SOCK=node_ID command

Or:

export SOCK=node_ID; command

where:

node_ID
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 are affected. For more information, see the LAN Configuration chapter in the TCP/IP User's Guide.

When running an executable, a Socket Manager is located by the following search order:

  1. The socket manager defined in the SOCK environment variable.
  2. A Tcpip manager running on your local node.
  3. A call to qnx_name_locate() (C Library Reference) to find a global Tcpip manager (sin gn displays a list of globally registered names).

If you don't want your Socket to be located in a global search by a utility on another node, start as:

Tcpip -L

[Previous] [Contents] [Index] [Next]