DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
Programming with the X/Open Transport Interface (XTI)

An example connection-mode client

The following code represents the connection-mode client program described in the section ``Connection-mode service''. This client establishes a transport connection with a server, and then receives data from the server and writes it to its standard output. The connection is released using the orderly release facility of the Transport Interface. This client communicates with each of the connection-mode servers presented in the guide.

   #include <stdio.h>
   #include <xti.h>
   #include <fcntl.h>
   

#define SRV_ADDR 1 /* server's well known address */

main() { int fd; int nbytes; int flags = 0; char buf[1024]; struct t_call *sndcall;

if ((fd = t_open("/dev/ticots", O_RDWR, NULL)) < 0) { t_error("t_open failed"); exit(1); }

if (t_bind(fd, NULL, NULL) < 0) { t_error("t_bind failed"); exit(2); }

/* * By assuming that the address is an integer value, * this program may not run over another protocol. */ if ((sndcall = (struct t_call *)t_alloc(fd, T_CALL, T_ADDR)) == NULL) { t_error("t_alloc failed"); exit(3); } sndcall->addr.len = sizeof(int); *(int *)sndcall->addr.buf = SRV_ADDR;

if (t_connect(fd, sndcall, NULL) < 0) { t_error("t_connect failed for fd"); exit(4); }

while ((nbytes = t_rcv(fd, buf, 1024, &flags)) != -1) { if (fwrite(buf, 1, nbytes, stdout) < 0) { fprintf(stderr, "fwrite failed\n"); exit(5); } }

if ((t_errno == TLOOK) && (t_look(fd) == T_ORDREL)) { if (t_rcvrel(fd) < 0) { t_error("t_rcvrel failed"); exit(6); } if (t_sndrel(fd) < 0) { t_error("t_sndrel failed"); exit(7); } exit(0); } t_error("t_rcv failed"); exit(8); }


© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 27 April 2004