C Board  

Go Back   C Board > General Programming Boards > Networking/Device Communication

Reply
 
LinkBack Thread Tools Display Modes
Old 04-29-2005, 12:42 PM   #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
verbena1 is offline   Reply With Quote
Old 04-29-2005, 12:48 PM   #2
and the hat of Jobseeking
 
Salem's Avatar
 
Join Date: Aug 2001
Location: The edge of the known universe
Posts: 21,647
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.

Salem is offline   Reply With Quote
Old 04-29-2005, 12:59 PM   #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?
verbena1 is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

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


All times are GMT -6. The time now is 10:34 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

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