Sponsored Content
Full Discussion: client /server pipes
Top Forums Programming client /server pipes Post 302228242 by tolkki on Saturday 23rd of August 2008 04:12:44 PM
Old 08-23-2008
client /server pipes

here is the concept:

the client reads a pathname from the standard input and writes it to pipe1.The server reads this pathname from the pipe1 and tries to open the file for reading.If the server can open the file ,the server responds by reading the file and writting it to pipe2;otherwise the server writes an error message to the same pipe.The client then reads from the pipe2 and writes it receives to the standard output

here is my code:

Code:
#include <stdio.h>
#include <string.h>
#define maxsize 1000

char buffer [maxsize];

void client(int readfd,int writefd)
{
   puts("give pathname:");
   gets(buffer);

   write(writefd,buffer,strlen(buffer));
   //sleep(10);
   while((read(readfd,buffer,strlen(buffer)))>0);
     printf("%s/n",buffer);

}

void server(int readfd,int writefd)
{
   FILE * fp;
   char line[100];
   //sleep(10);
   read(readfd,buffer,strlen(buffer));
   fp=fopen(buffer,"r");
   if(fp==NULL)
   {
       strcpy(buffer,"cannot oepn file");
       write(writefd,buffer,strlen(buffer));
   }
   else
     while(fgets(line,100,fp)!=NULL)
       write(writefd,line,100);
}

int main()
{
    int pipe1[2],pipe2[2];
    int childpid;
    int status;
    pipe(pipe1);
    pipe(pipe2);
    childpid=fork();
    if(childpid>0)
    {
        close(pipe1[0]);
        close(pipe2[1]);
        client(pipe2[0],pipe1[1]);
        wait(&status);
        exit(0);
    }
    else
    {
        close(pipe1[1]);
        close(pipe2[0]);
        server(pipe1[0],pipe2[1]);
        exit(0);
    }

}

Actually ,I understand that there might be some problems with race conditions that's why i put 2 sleep commands but still doesn't work..
generally i want to sychronize the read and write commands of the client and server but I don't know how...
if someone has the time to see the code and give me some advice,it will really be appreciated.....thanks in advance..
 

10 More Discussions You Might Find Interesting

1. Filesystems, Disks and Memory

PIPEs and Named PIPEs (FIFO) Buffer size

Hello! How I can increase or decrease predefined pipe buffer size? System FreeBSD 4.9 and RedHat Linux 9.0 Thanks! (1 Reply)
Discussion started by: Jus
1 Replies

2. UNIX for Dummies Questions & Answers

client/server

Hi, yes i belong to that duummies group of people so here is the question that i need someone to explain it to me and posiblly to answere it to me in a plain english. This is the question: Describe the concept of “client-server” software. Discuss what each side of the equation... (2 Replies)
Discussion started by: bole
2 Replies

3. Shell Programming and Scripting

Client-server

Hi, I have installed the vmware server on my debian os and has several clients connected to it. Is there any script that enable the server to restart the client automatically?? Can anyone help. Thanks in advance (3 Replies)
Discussion started by: kanexxx
3 Replies

4. Programming

Client/Server Socket Application - Preventing Client from quitting on server crash

Problem - Linux Client/Server Socket Application: Preventing Client from quitting on server crash Hi, I am writing a Linux socket Server and Client using TCP protocol on Ubuntu 9.04 x64. I am having problem trying to implement a scenario where the client should keep running even when the... (2 Replies)
Discussion started by: varun.nagpaal
2 Replies

5. Windows & DOS: Issues & Discussions

Office server => laptop =>client server ...a lengthy and laborious ftp procedure

Hi All, I need your expertise in finding a way to solve my problem.Please excuse if this is not the right forum to ask this question and guide me to the correct forum,if possible. I am a DBA and on a daily basis i have to ftp huge dump files from my company server to my laptop and then... (3 Replies)
Discussion started by: kunwar
3 Replies

6. Programming

please help a problem in client-server ipc message 2 pipes communication simple example

I want to have a message send & receive through 2 half-duplex pipes Flow of data top half pipe stdin--->parent(client) fd1--->pipe1-->child(server) fd1 bottom half pipe child(server) fd2---->pipe2--->parent(client) fd2--->stdout I need to have boundary structed message... (1 Reply)
Discussion started by: ouou
1 Replies

7. Programming

Client Server C

Hello, Please I would create a client and a server in C that communicate frequently. The client sends "hello message" to the server, the server waits a few minutes and sends a "hello message" to the client, the client sends again "hello server ".. etc up to 15 minutes Can you guide me... (3 Replies)
Discussion started by: chercheur857
3 Replies

8. UNIX for Dummies Questions & Answers

Client server C

Hello, Please, is there on unix.com the source code of a client C and server C: as shown in following figure: File:InternetSocketBasicDiagram zhtw.png - Wikipedia, the free encyclopedia Thank you so much for help (1 Reply)
Discussion started by: chercheur857
1 Replies

9. Programming

Trouble with pipes in chat client on linux

I'm writing a simple chat client in C++ on linux to connect to a win32 chat server on my computer also written in C++. I'm confident that the server works but the chat client is giving me some trouble. I'm forking the chat client and have one process dealing with incoming messages and another... (14 Replies)
Discussion started by: vindy
14 Replies

10. Shell Programming and Scripting

Sftp script for dev server to client server

hi, i am new to unix, cuold u send some sftp acripts to send files to dev server to clint server, (1 Reply)
Discussion started by: Koti.annam
1 Replies
IMAPPROXYD(8)							 IMAP proxy daemon						     IMAPPROXYD(8)

NAME
imapproxyd - IMAP proxy daemon SYNOPSIS
imapproxyd [ -f <config file name> ] [ -p <pidfile name> ] DESCRIPTION
This manual page documents briefly the imapproxyd command. This manual page was written for the Debian distribution because the original program does not have a manual page. UP-ImapProxy proxies IMAP transactions between an IMAP client and an IMAP server. The general idea is that the client should never know that it is not talking to the real IMAP server, but ImapProxy caches server connections. ImapProxy was written to compensate for webmail clients that are unable to maintain persistent connections to an IMAP server. Most webmail clients need to log in to an IMAP server for nearly every single transaction; This behaviour can cause tragic performance problems on the IMAP server. ImapProxy tries to deal with this problem by leaving server connections open for a short time after a webmail client logs out. When the webmail client connects again, ImapProxy will determine if there is a cached connection available and reuse it if possible. FILES
By default, UP-ImapProxy reads /etc/imapproxy.conf on startup. This can be changed by using the -f option Unless foreground_mode has been enabled, UP-ImapProxy will write its PID to to a PID-file. It defaults to /var/run/imapproxy.pid, but can be overridden with the -p option SEE ALSO
pimpstat(8), AUTHOR
This manual page was written by Jose Luis Tallon <jltallon@adv-solutions.net>, for the Debian GNU/Linux system (but may be used by others). Dave McMurtrie Mar 12, 2004 IMAPPROXYD(8)
All times are GMT -4. The time now is 03:36 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy