actually, I just want the idea here. I have a server, a client . client will request to display the files names in its directory(server's current directory). server will send the list.

my thinking : system command will be used here. when clinet enter "-ls" then server will have system() call and will get all the file names. but my problem is that how it will send these files name to the client ? can you please give me idea ? thanks.

Recommended Answers

All 5 Replies

system will not provide you with output. You need to using something like popen or the longhand version of that using fork and exec. These tools allow you to capture the output of a program that is run - you would use that output to construct a message to be returned to the client.

commented: +10^99 votes :-) thanks alot. (Y) +2

can you please elaborate it more ? how can i use popen and fork here ?

I would not combine popen and fork. I would use only popen as it combines the use of several other functions (such as fork and exec) to accomplish it's tasks. Here are several examples of using popen.

people like you has made daniweb.com valuable. thank you sir!! it is really damn helpful to me. saved my many hours. thanks. Can you tell me one thing here that if i want to have a server and many clients and one client can communicate with other client thorugh server. then how can i implement server so as to do achive the task ? any idea ?

What you as there is a failrly involved task.

In the simplest case where you only want to send a command from A (client 1) through B (the server) to C (client 2) without a reply you just somehow encode the ultimate destination in the original message. That way, upon receiving a message, you simply forward it along to the next node that gets you closer to the destination client.

When you want to communicate a response or have some feedback from client 2 then you need to support a mechanism to 'remember' who originally sent the message (client1) and what needs to be returned. The reply is sent back the same as the initial message but with the source and destination reversed.

This is very similar to how packets are routed in an IP-based network (where your 'server' would act as a router). There is a source and destination that are used to 'route' packets along a path. Intermediate nodes (routers or otherwise) use this information in combination with a routing table to determine the next best move in getting closer to a particular destination node.

You may also consider a distributed message system - something like ZeroMQ or RabbitMQ. These provide services overwhich you can implement a command language without having to consider the details of how the messages are actually handled.

It depends on what you ultimately want to accomplish and how you want to go about it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.