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

An example read/write client

The following code represents the connection-mode read/write client program described in ``A read/write interface''. This client establishes a transport connection with a server and then uses cat(C) to retrieve the data sent by the server and write it to its standard output. This client will communicate with the connection-mode servers presented in ``An example connection-mode server''.

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

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

main() { int fd; 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); } if (ioctl(fd, I_PUSH, "tirdwr") < 0) { perror("I_PUSH of tirdwr failed"); exit(5); }

close(0); dup(fd);

execl("/usr/bin/cat", "/usr/bin/cat", 0);

perror("execl of /usr/bin/cat failed"); exit(6); }


© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 -- 02 June 2005