![]() |
C socket : how Execute shell program from server, and passing the output to client?
Dear,
I am a new member of this forum. I'm learning about Linux C socket programming right now and got problem about command line execution from C program. I have one server daemon (server.c) and client program (client.c). When server running, client try to execute a command line that describe in argument of client command line. Is there any method how to make server wait for command line result output, and then send all of result to client? Please let me know. this is my example scenario : From server side : Code:
$ ./server 9999From client side : Code:
$./client 192.168.1.1 9999 cat /proc/loadavgCode:
$./client 192.168.1.1 9999 snmpwalk -c public 192.168.1.20 1.3.6.1.2.1.2.2.1another example : Code:
$./client 192.168.1.1 9999 commanderrrBest regards, Denny Z |
If I understand you correctly, you want the server to wait till the client has processed the command and dumped its output.
If so, I do not really understand the wait part. What do you want to happen after the wait? And what happens now? And how do you want it to work when client and server run on different computers. Usually servers run forever. A client connects to the server, the server accepts the connection, communication happens, and when the client is done, it disconnects. The server will keep on running, waiting for new connections. Normally, you will define a commnication protocol. In your case, the client will send a command (or reply) to the server that it's done with what it's doing. |
If I understand you correctly, you want to:
1. enter a 'shell type' command in the client 2. client will send the request to the server via a socket 3. the server will execute the command 4. results sent back over a socket to the client 5. display the results on the client? Is this correct? I'm assuming this is some sort of exercise since there are tools that will do this for you already, (rsh). Assuming that you have the sockets down, it sounds like you are seeking the popen command to execute and save the resutls, when then can be sent back to the client. If this will be used for anything other than an exercise or perhaps a school project (yes it reeks), please think of the security implications here. It really exposes your system. |
Quote:
|
To elaborate a bit more on the communication protocol. Usually clients instruct servers to do thing and the servers reply.
e.g below is how an ftp server and ftp client communicate (not 100% accurate) Code:
server waits for connection fro clientCode:
server waits for connection from client |
Quote:
|
Quote:
Quote:
Quote:
Thank you for your help. regards, |
| All times are GMT -5. The time now is 05:15 AM. |