DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
Developing applications using XTI or TLI

Client pseudo-code

This client sends data to and receives data from the selected server.

#include <xti.h>
#include other needed header files

extern int t_errno;

main (int argc, char *argv[]) {

/* Declare data structures needed for operations on the transport provider endpoint. */

/* Declare the data structure that contains the well-known address of the server. Both the type and the value of "server_address" must be transport-specific. This example assumes that they have already been defined appropriately (using "typedef" and "#define", for example). TRANSPORT_ADDRESS server_address = WELL_KNOWN_SERVER_ADDRESS;

/* Declare other data structures. */

/* Open the transport provider, using the appropriate device name, and receive a file descriptor in return that denotes that endpoint. */ fd = t_open(device_name, ... )

/* Have the transport provider bind an arbitrary transport address (which is transport-specific) to the endpoint. */ t_bind(fd, NULL, NULL);

/* Allocate the data structure needed in the call to connect to the server. */ connection_info = t_alloc(fd, T_CALL, T_ADDR);

/* Fill in the data structure with the well-known address of the server. */ connection_info->addr.len = sizeof(server_address); connection_info->addr.buf = &server_address;

/* Connect to the server, passing in its well-known address. */ t_connect(fd, connection_info, NULL);

while (true) {

/* Send data to the server. */ t_snd(fd, &data_to_send, sizeof(data_to_send), &flags);

/* Receive data from the server. */ t_rcv(fd, &data_to_send, sizeof(data_to_send), &flags);

/* Time to exit? */ if (time_to_exit == /* some suitable expression that returns zero if it's not time to disconnect and non-zero otherwise */) break; }

/* Disconnect */ t_snddis(fd, NULL);

/* Close the transport endpoint. */ t_close(fd); }


Next topic: Server pseudo-code
Previous topic: Pseudo-code examples

© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003