Running RPC over TCP or UDP

# Using the Internet: TCP and UDP

Remote procedure calls can run over TCP/IP and UDP/IP services. This section gives common information about using TCP or UDP, whatetever machine you are on. You should also look up specific information about the machine you are using .

## Introduction: Internet addressing

To use TCP or UDP, your RPC addresses must end in the medium names whereas UDP is a datagram protocol. The RPC system uses one or the other as instructed. UDP may be faster but is not available on some machines. TCP is stream-oriented and so, when data flow is mainly in one direction, PRAGMA CAST may used to stream messages for extra speed.

Node
  A node on the internet is identified either by a name (e.g VXCRNA ), or if the name is not known locally, by a set of four numbers separated by dots (e.g. 141.4.12.10 ) Node names are normally in lower case on systems where this is significant. (See file /etc/hosts on unix).
Port
  A port is an endpoint of communication within a node. Within a node there are many ports, identified by decimal numbers 0 to 32767. Ports 0 to 1023 are reserved for so called "well known port" numbers. (See file /etc/services on unix). Priviledge (SYSPRV under VMS) is required to use a number below 1024.
  Port numbers of 1024 and above are free for user applications, although it is not possible to use one already in use.
  To communicate, one side (normally the server) must either establish a numbered port and the other side (normally a client) must make a connection to it.
  If a port number is unspecified for a server, the RPC system will dynamically chose the first free port in the range 5000 to 5999 (decimal).
Connection
  There may be many connections to a port. A connection is normally established at initialisation time, but is the RPC address is preceded by a "#" hash character, the RPC system will open and close a connection for each call. This will save connections when there are very many machines but take more time.

## Defining the clientele for a server

A server may service multiple clients. The address of the client it is to service starts with an asterisk "*" to indicate this. Then follow the node number or name, a colon, and the number of the port at which the server is to listen. The server creates a local port of that number, and waits for connections from the given node.

            *vxcrna:777.tcp         Service multiple clients on node vxcrna.
                                    Establish a local port number 777.
                                    Use TCP

If the node is omitted, the server will service connections from any node:

            *:777.tcp                Service multiple clients on any nodes.
                                    Establish a local port number 777.
                                    Use TCP

The colon ":" must always precede the port number.

If the colon and port number are omitted, the server will dynamically find a free port number:

            *.tcp                   Service multiple clients on any nodes.
                                    Find a free port starting at 5000.
                                    Use TCP

In this case, a name server is necessary for the client to find the correct port for the given service using a name server, for example.

## Staring servers automatically : The Internet Daemon

It is possible to arrange for servers to be started automatically (under unix or VMS, at least). This is done by the internet daemon process which normally runs on a machine running TCP/IP.

In order to do this, you must arrange that your server program is in the database used by the inet deamon, "inetd". This will require privilege. You should read the documentation for your system. On unix, see /etc/inetd.conf and man inetd .

On VMS with WIN/TCP, see TWG$TCP:[NETDIST.ETC]SERVERS.DAT and read , around p154. for details of how to do this, and how to start and stop the daemon if necessary.

The program which is started by the daemon should be written as normal RPC server program, with the clientelle explicitly put in as

            .tcp                    Use connection handed down from
                                    the internet daemon

In this case, when a connection is made to the server port given in the deamon database, the daemon starts your server and passes it the connection. The server program in this case handles only one client per task.

## Defining a server for a client

On the client side, to define the address of a remote package, one must quote the server port number and the node name:

            vxcrna:777.TCP            Node VXCRNA, port 777.

            121.12.2.1:777.TCP        Node 121.12.2.1, port 777

            #vxcrna:777.TCP           Node VXCRNA, port 777
                                      (reconnect for each call)

The port number quoted by the client must, of course, be the same as the one established by the server.