Question on returning stdout from a server

This is a discussion on Question on returning stdout from a server within the Networking/Device Communication forums, part of the General Programming Boards category; I need some C/Unix networking help, I'm working on a assignment in a unix environment that has two parts. Part ...

  1. #1
    Registered User
    Join Date
    Apr 2005
    Posts
    2

    Question Question on returning stdout from a server

    I need some C/Unix networking help,

    I'm working on a assignment in a unix environment that has two parts.
    Part one implement a simple "shell" that parses a command and its arguments and then executes it, or if a pipe character is used ("|") parse the left side, parse the right side, and then manually pipe (using close() and dup()) and return this to a command line of my making (in my case my prompt is myShell

    I have that done but now I need to implement it using networking. I have a client and a server and my setup is that the client connects to the server and the client prints out the prompt "myShell: " I can send a command and it works on the server end but I would like to know how to send the servers output of the command back to the client. I've looked around the internet and through my books (Richard Stevens Unix Networking book) and I can't find a way to do this unless I'm just missing something. I thought about maybe using dup() to make a copy of the input-send to the server-run my parse and execute functions-copy the output and send to to the client but I don't know how to do this. If I can send out this output is there a way to send my "myShell:" prompt directly from the server and save my client the trouble?

    Any help would be appreciated

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,821
    I imagine you dup() using socket descriptors instead of using the descriptors created by say pipe()
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Apr 2005
    Posts
    2
    I'm not sure on the syntax though,

    I know that in client its called sockfd, and in server newsockfd.
    and this is where my server executes code after a connection:

    Code:
    for (;;) {
    
    		/* accept a connection */
    
    		if ( (newsockfd = accept(sockfd, NULL, NULL)) == -1) {
    
    			perror("accept call failed");
    
    			continue;
    
    		}
    
    
    
    		/* spawn a child to deal with the connection */
    
    		if (fork() == 0) {
    
    			while (recv(newsockfd, buf, MAXLINE, 0) > 0) {
    
    				parse(buf, args1, args2);
    
    				execute(args1, args2);
    
    				send(newsockfd, buf, MAXLINE, 0);
    
    			}
    
    			/* when client is no longer sending information
    
    			the socket can be closed and the child process
    
    			terminated */
    
    			close(newsockfd);
    
    			exit (0);
    
    		}
    Do i dup() the stdout like i would for a pipe?
    close(1);

    dup(p[1]);

    close(p[0]);
    If so what am I assigning it too to send it back to the client?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Where's the EPIPE signal?
    By marc.andrysco in forum Networking/Device Communication
    Replies: 0
    Last Post: 12-23-2006, 08:04 PM
  2. winsock server question?
    By kocho in forum Windows Programming
    Replies: 2
    Last Post: 02-02-2006, 01:52 PM
  3. char* returning question
    By Devil Panther in forum C Programming
    Replies: 19
    Last Post: 08-29-2005, 01:50 PM
  4. SWEBS Web Server
    By nickname_changed in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 09-22-2003, 03:46 AM
  5. a question on server stuff
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 9
    Last Post: 10-05-2001, 03:54 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21