![]() |
| | #1 |
| Registered User Join Date: Apr 2005
Posts: 2
| 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 | |
| | #2 |
| and the hat of Jobseeking 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() |
| Salem is offline | |
| | #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);
}
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 | |
![]() |
| Thread Tools | |
| Display Modes | |
|
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 |