Solved

Simple Client-Server Data Transfer using TCP

Posted on 2003-11-05
18
2,572 Views
Last Modified: 2007-12-19
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
0
Comment
Question by:snehanshu
  • 9
  • 8
18 Comments
 

Assisted Solution

by:opreacatalin
opreacatalin earned 50 total points
ID: 9686063
Try to follow and understand SimpleClientServer Demo from Indy package (you can get it from http://www.indyproject.org/indy/demodownloads/I9D6_Demos_24Nov02.zip or you allready have it in delphi\demos\indy directory). This and all other demos from Indy will help you out!

After you "read" those demos, you can post here a more pertinent question.
0
 
LVL 5

Author Comment

by:snehanshu
ID: 9686343
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
0
 
LVL 6

Accepted Solution

by:
swift99 earned 450 total points
ID: 9691744
You have not said how many connections you want, or the degree of fault tolerance.

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.

Anything sent to x.x.x.0 will be broadcast, so all machines on the subnet will receive it.

I recommend getting ICS and Midware and looking at the examples.  Nothing is better documentation than working code that you can run and use the debugger to watch.   http://overbyte.delphicenter.com
0
 
LVL 5

Author Comment

by:snehanshu
ID: 9691990
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.
0
 
LVL 6

Expert Comment

by:swift99
ID: 9694121
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.  
0
 
LVL 5

Author Comment

by:snehanshu
ID: 9695166
>>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
0
 
LVL 6

Expert Comment

by:swift99
ID: 9695485
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.
0
 
LVL 5

Author Comment

by:snehanshu
ID: 9695581
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 :-)
0
 
LVL 6

Expert Comment

by:swift99
ID: 9695738
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.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 5

Author Comment

by:snehanshu
ID: 9695847
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.
0
 
LVL 6

Expert Comment

by:swift99
ID: 9695928
You guys aren't using something like Radia to manage and distribute your software?
0
 
LVL 6

Expert Comment

by:swift99
ID: 9695945
You can always have a telnet server on the user box - check out the Telnet demo in ICS (http://overbyte.delphicenter.com).
0
 
LVL 5

Author Comment

by:snehanshu
ID: 9696164
>>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
0
 
LVL 6

Expert Comment

by:swift99
ID: 9696545
I would also check out ICS, which is an alternative product that hits a similar niche to Indy.
0
 
LVL 6

Expert Comment

by:swift99
ID: 9699200
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.
0
 
LVL 5

Author Comment

by:snehanshu
ID: 9699262
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
0
 
LVL 6

Expert Comment

by:swift99
ID: 9701421
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.
0
 
LVL 5

Author Comment

by:snehanshu
ID: 9713800
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
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This video discusses moving either the default database or any database to a new volume.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now