Network Interface Guide


The example server transfers a log file to the client over the transport connection. The client receives the data and writes it to its standard output file. A byte stream interface is used by the client and server, with no message boundaries. The client receives data by the following:

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

The client repeatedly calls t_rcvv(3NSL) to receive incoming data. t_rcvv(3NSL) blocks until data arrives. t_rcvv(3NSL) writes up to nbytes of the data available into buf and returns the number of bytes buffered. The client writes the data to standard output and continues. The data transfer loop ends when t_rcvv(3NSL) fails. t_rcvv(3NSL) fails when an orderly release or disconnect request arrives. If fwrite(3C) fails for any reason, the client exits, which closes the transport endpoint. If the transport endpoint is closed (either by exit(2) or t_close(3NSL)) during data transfer, the connection is aborted and the remote user receives a disconnect request.