- Level: University Degree
- Subject: Mathematical and Computer Sciences
- Word count: 501
3SFE518 Computer System Organisation - Piping
Extracts from this document...
Introduction
Coursework for:
Computer System Organisation
3SFE518
Malshani Nanayakkara
2007020
CONTENTS
Introduction – About the Piping 3
Program Listing 4
Screenshots 7
ABOUT THE PIPING
In order to be able to communicate between two terminals, pipes have been used. As pipes are FIFO structure (First In First Out), it is well suited to be used for such an application. Two pipes are created, one used to define a communication channel from the server terminal to the client and the other to define a communication channel from the client terminal to the server terminal. Lets call these two pipes, np1 and np2, where np1 is the connection from the client to the server.
In the program running on the server terminal, the pipe np1 is opened in the read only mode.
Middle
{
int ReadFromPipe, WriteToPipe, return_val, NumChar;
char buffer[MAX_BUF_SIZE];
// Create the first named pipe
return_val = mkfifo(NP1, 0666);
if ( return_val == -1 && errno != EEXIST)
{
perror("Error creating the named pipe");
exit(1);
}
//creates second named pipe
return_val = mkfifo(NP2, 0666);
if (return_val == -1 && errno != EEXIST)
{
perror("Error creating the named pipe");
exit(1);
}
/* Open the first named pipe for reading */
/* Open the second named pipe for writing */
ReadFromPipe = open(NP1, O_RDONLY);
WriteToPipe = open(NP2, O_WRONLY);
while(1)
{
/* Read from the first pipe */
NumChar = read(ReadFromPipe, buffer, MAX_BUF_SIZE);
Conclusion
//Reference: http://developers.sun.com/solaris/articles/named_pipes.html
#include <stdio.h>
#include <errno.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "fullduplex.h" /* For name of the named-pipe */
int main()
{
int WriteToPipe, ReadFromPipe, NumChar;
char rdbuffer[MAX_BUF_SIZE];
/* Open the first named pipe for writing*/
/* Open the second named pipe for reading */
WriteToPipe = open(NP1, O_WRONLY);
ReadFromPipe = open(NP2, O_RDONLY);
printf("Start conversation. Say something: ");
while(1)
{
gets(rdbuffer);
/* Write to the pipe */
write(WriteToPipe, rdbuffer, strlen(rdbuffer));
/* Reads from the second pipe */
NumChar = read(ReadFromPipe, rdbuffer, MAX_BUF_SIZE);
rdbuffer[NumChar] = 0; //ends the string by placing '0' in the next slot
printf("Server says: %s\nYou say: ", rdbuffer);
}
}
SCREENSHOTS
This student written piece of work is one of many that can be found in our University Degree Software Engineering section.
Found what you're looking for?
- Start learning 29% faster today
- 150,000+ documents available
- Just £6.99 a month