8. Socket Library

Introduction

This chapter describes the Socket Library to use for your particular programming application.

TCPware provides a Socket Library if you are running a version of VMS earlier than 5.3 or are using the Remote Procedure Call (RPC) routines. However, Process Software does not recommend that you use the TCPware Socket Library for later versions of OpenVMS.

OpenVMS provides a C Socket Library you should use for VMS Version 5.3 and later. VMS provides a collection of VAX C, DEC C, and DEC C++ subroutines that closely emulates the UNIX socket functions.

 

Note! The TCPware socket library is deprecated and unsupported.

 

 

See VAX C Run Time Library Manual or DEC C Language Reference Manual for information on these socket library routines.

Transitioning to the C Socket Library: Include (Header) Files

OpenVMS provides header files for its C socket library that are similar to those provided by the obsolete TCPware socket library.

To use the VMS C Socket Library header files:

·         If you are transitioning an existing VAX C socket application, change any #include statements for TCPware's header files to reference VMS's header files. For example:

#include "tcpware_include:netdb.h"

becomes:

#include <netdb.h>

Then compile as follows:

o   On the VAX C command line:

$ cc prog.c

o   On the DEC C command line for VAX:

$ cc /stand=vaxcprog.c

o   On the DEC C command line for Alpha and I64:

$ cc /stand=vaxc/nomember_align/assume=noalignedprog.c

·         If you are porting or developing an ANSI C or C++ application, use the VMS header files as shown above. Then compile the application (in the case of DEC C, omit the
/stand=vaxc option).

If you are developing a new program using DEC C, compile using:

 $ cc /prefix_library_entries=all_entriesprog.c

Transitioning to the C Socket Library:
Linking Applications

You can then link against VMS's C socket library as follows:

·         For VAX C:

$ link prog,sys$input/options tcpware:ucx$ipc/lib –

_$ sys$share:vaxcrtl/share

·         For DEC C on the VAX, Alpha and I64, and for DEC C++:

$ link prog

Sample Programs

The following sample programs are included in the TCPWARE_COMMON:[TCPWARE.EXAMPLES] directory:

·         TCP_SOCKET_CLIENT.C

·         TCP_SOCKET_SERVER.C

·         UDP_SOCKET_CLIENT.C

·         UDP_SOCKET_SERVER.C

The TCP_SOCKET_CLIENT.C and TCP_SOCKET_SERVER.C pair of programs provide a self-declared ECHO server that sequentially accepts client connections and echoes back the client messages. The UDP_SOCKET_CLIENT.C and UDP_SOCKET_SERVER.C pair of programs provide a self-declared DISCARD server that can receive (and discard) datagrams from multiple clients.

These programs are functionally equivalent to the BGDRIVER sample programs in Chapter 2, UCX Compatibility Services.

To build any one of these applications using DEC C, enter:

$ CC/DECC/PREFIX=ALL filename
$ LINK filename

To build any one of these applications using VAX C, enter:

$ CC/VAXC filename
$ LINK filename, TCPWARE:UCX$IPC/LIB, SYS$INPUT/OPTIONS -
_$  SYS$SHARE:VAXCRTL/SHARE

Debugging programs that use the C socket library

The logical TCPWARE_SOCKET_TRACE can be defined to get a trace of socket library operations and status values returned from TCPware to aid in debugging of applications. The details of the interpretation of the logical are in the table below:

number

·         1 - control operations

·         2 - read operations

·         4 - write operations

These values can be ORed together to get any combination of operations.

anything else

Interpreted as a (partial) file specification with the default specification being SYS$SCRATCH:TCPWARE_SOCKET_process_name.LOG

This can be useful for services that are started up by NETCU or another listening service and that create separate processes. The logical can be defined at the SYSTEM level and the socket library routines will generate a separate log file for each process. When this format is used the log consists of all three classes (control, read and write) operations.