Link to home
Start Free TrialLog in
Avatar of snehanshu
snehanshu

asked on

Simple Client-Server Data Transfer using TCP

Hello Experts.
  I have never done socket programming. I want to create a simple application that has the following functionality:

I would like to have a controller (called System A) which can instruct all machines to do some task and return the result.

1) From system A, I want to send some string to another system (System B, whose IP address I know and which has perhaps this same program running)
2) On System B, I want to read the received string, do the necessary processing depending on what was sent, and send a reply back to the system A.
3) When system B sends a response, System A could save the response to a text file aling with the detail of the system that sent the response.
4) Also, if possible, I want to be able to broadcast a common message from system A to all systems that are running my application so that they could send a response back that System A can log.

  I am very unfamiliar with TTcpServer, TTcpClient of Delphi 7 but intend to use these for my application. Ofcourse, if there are simpler ways to do this, then the suggestions would be welcome. If there are things I missed out in the requirements, please do point those out :-)
  But I would need a very detailed explanation because I have to get the job done!
Thank you,
...Snehanshu
SOLUTION
Avatar of opreacatalin
opreacatalin

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of snehanshu
snehanshu

ASKER

opreacatalin,
Thank you for the link. I downloaded the demos.
I'd love to have the sort of spoon-feeding c/c++ newbies have here. Aren't 500 points and the satisfaction of enlightening some one worth it?
All Delphi knowledge I have is by years of similar trial-and-error (and Marco Cantu!). But for Client-Server, I'd like to learn from experts' experiences.

Here are some doubts I have (I'd prefer to have a solution as a whole, but perhaps this might you help understand my level of expertise):
1) Should I use a client component to send a message and server to receive?
i.e. if the terminals want to be able to send some message (Command) to the controller, should the terminals have a client component for this?
2) How can I broadcast a message and how can I accept the broadcasted message?
3) What are the event sequences? Like OnConnect, OnExecute etc.?

Please don't tell me I am stupid (I know that). Rather tell me what the wise would do!
:-)
Cheers,
...Shu
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
swift99,
>>If you want a high degree of fault tolerance, then i would run a listener (aka "server") socket on both client and server.  That way, either end can initiate a (connect - work - disconnect) session.

Thank you. I would like to have more such comments. Since I am a beginner, I would like to know the factors to be considered before I begin coding.

Here's the exact Idea:
I am trying to create a work-monitoring application (not that I agree with the concept, but still, a project is a project).
It would essentially be a service running on every PC in my office which tracks the time a person was actually working by hooking to keyboard & mouse events.
Well, I've got the hook part sorted out: my service can log the time worked for each machine in the registry.
Now, I am stuck at the reporting part. I want an app to be running at one location that can query each system that has my service running to get the work-time.
Also, the services may periodically send work-time updates to my app.
My app would then update these to a database (and perhaps send an ack to the service).

I hope this problem definition is not too complex to guide. I know I can google for client-server and learn concepts, but I feel the learning would be better if some body guided me how exactly I should go about given this problem definition (Not the code, but atleast analyze my problem and guide me as to what you would have done if you were to do this).

Please help,
...Shu
P.S.
  I am looking and searching for links now.
You can either poll the desktop machines, or the desktop machines can submit reports.  But making both the desktop and the client machine servers, you can use both strategies.

I know, you're just doing a job, but I'm going to put my two cents worth in anyways.  This way of measuring work will be counter productive, since only a limited number of classes of work can be measured, and those are often the end result pieces rather than the real "work".  For example, good programmers spend 70% or more of their work time thinking and designing, and only about 30% actively engaged with the computer.  
>>For example, good programmers spend 70% or more of their work time thinking and designing
I know that the first person to be badly affected would be me! I don't think this concept would be a success, but I took up the project because I found the hook part challenging.
Unfortunately, this project has another side of which I have very little clue and that's slowed down my pace a lot. That's why I need help on the reporting part.
...Shu
How many machines on the network?  100, 1000, 10000?

In this case, I would be tempted to use a KISS strategy.

Simply hook up to a DBMS using dbExpress and dump your data using TQuery components.

Batch up results and dump them every 10 minutes or so, so that you don't generate huge amounts of network traffic.  Should be good to 10,000 users on a 100 Mbit LAN.
swift99,
  Your KISS is a great option. But a few conditions are:
1) No smart users should be able stop my service (and if they do, I should be able to determine that)
2) I should be remotely able to configure the SQL database username & passwords
  Any suggestions for KISSing these?
...Shu
P.S.
>>How many machines on the network?
   Initial testing with around 50 of us. "IF" found satisfactory, then about 1000 users. "IF" Very good, then 40,000 :-)
1. That is a function of NT security.  Since XP is an NT kernel, it is covered.  Handle the Windows Kill event as much aas you can, remembering that ultimately the OS has the authority to simply dump the process out of memory.

2. Your app user name would have its own password.  You do not need a user name for each user.  The app/service should monitor the current logged in user name and save that, but login authority should be per the app.  To make it configurable, use a properties file.  Compress it with gzip, using the free download components and DLLS to do that.  To the user it will appear to be a binary file, and since it is compressed any attempts to alter it will render it useless.  Prevention of this is also governed by NT/XP security.

Remote configuration consists of dumping a gzipped ini file on the system in the right place.

3. For 40,000 users you will need to look at bandwidth, propagation delay, and server performance really closely.  You may need to move to a midrange server, say IBM series 6000 or AS/400.
swift99,
  For #2, I meant that
1) All applications will use the same username and password
2) If I change my SQL server, I should not be required to go to each machne and re-configure the settings (like copy the password file). Instead, I would like my service to accept a "command" from a controller which instructs it that the password has been changed and supplies it with a new set of SQL server information.

For #3, well 40,000 users won't use the same server, I guess we would split the load department-wise (Around 500 to 1000 max). But that's only if everybody finds the concept useful.
You guys aren't using something like Radia to manage and distribute your software?
You can always have a telnet server on the user box - check out the Telnet demo in ICS (http://overbyte.delphicenter.com).
>>You guys aren't using something like Radia to manage and distribute your software?
I don't know whar Radia is :-(
The utility would be a small in-house project.

Also, I guess this thread is perhaps getting way off-track.
For this question:
Simple Client-Server Data Transfer using TCP
I guess what I can summarize upto now is that
1) One needs to have some basic concepts clear to begin such a project.
2) Indy components can be looked into for Delphi 7
http://www.indyproject.org/indy/demodownloads/I9D6_Demos_24Nov02.zip 
3) Mastering Delphi 5 has Socket Programming with Delphi section in Internet Programming chapter (I discovered this just now). This could be a god place to start.
4) If you want a high degree of fault tolerance, then i would run a listener (aka "server") socket on both client and server.  That way, either end can initiate a (connect - work - disconnect) session.
5) Anything sent to x.x.x.0 will be broadcast, so all machines on the subnet will receive it.
Hey, looks like I am much more enlightened than I was when I posted.
I'll read Socket Programming stuff and ask some relevant questions in perhaps a day or two so that this thread becomes a bit more useful for others.
Thank you opreacatalin and swift99.
...Snehanshu
I would also check out ICS, which is an alternative product that hits a similar niche to Indy.
Radia is a product to manage enterprise software distributions.  You deposit files on a server and register them, and Radia makes sure that they get to the machine they are supposed to go to.  It, or one of its competitors, is absolutely necessary for a company larger than a few dozen PC's.
swift99,
  It seems we do have some such thing running on all machines. But to use that, I would need to take help of the network support and get entangled in a long hierarchy of premissions which I simply cannot afford (time wise). I am a programmer and I want to do it all myself :-)
...Snehanshu
Too bad ... if you make use of those resources they can save you a huge amount of time in design, construction, and support.  So many problems just go away for the cost of a little bit of paperwork and a few nice lunches.  If you stay on the good side of the deployment admins, it makes life so much easier.
opreacatalin and swift99,
  I screwed up my home PC and looks like its going to be quite some time before I resume working on this.
  I am closing this question for now. Thank you for your time and help.
...Snehanshu