?
Solved

Indy Server/Client Example

Posted on 2006-06-05
5
Medium Priority
?
3,378 Views
Last Modified: 2007-12-19
Hello,

I need a Clear Example of Indy10 Server/Client Application with following functions:

- Send Command from Client to Server
- Send Command from Server to Client
- Send a Long Text (TStrings) from Client to Server Like a Memo Contents and from Server to Client



Thanks
0
Comment
Question by:k4hvd77
  • 2
  • 2
5 Comments
 
LVL 17

Expert Comment

by:TheRealLoki
ID: 16838256
I've got a couple of demos here
https://sourceforge.net/projects/internetdemos/
you can still send long text, simply by doing
IdTCPClient1.IOHandler.Writeln(memo1.lines.text);
and just use readl to get it back

0
 
LVL 2

Expert Comment

by:Mainiacfreakus
ID: 16839003
If there isn't anything in the demos that help you, then tell me...

I can prob write an easy one for you.
(But not before saturday)

Mainiacfreakus
0
 
LVL 4

Author Comment

by:k4hvd77
ID: 16840573
Hello,
I can just find to Fils:

       Delphi5Indy10MultiFileDownloaderV1_1.zip
       Delphi7Indy9MultiFileDownloaderV1_1.zip

Non of them uses TCP Server or Client!!!! And I need a simple Example!!!!!
0
 
LVL 17

Accepted Solution

by:
TheRealLoki earned 2000 total points
ID: 16841014
look harder :-) in the v1.0 directory
https://sourceforge.net/project/showfiles.php?group_id=168004&package_id=191385&release_id=419146

client
===

var
    i: integer;
    s: string;
begin
    IdTCPClient1.Connect;
    s := IdTCPClient1.ReadLn;
    if s = 'NAME' then IdTCPClient1.IOHandler.Writeln('BOB');

    IdTCPClient1.IOHandler.Writeln('TIME');
    s := IdTCPClient1.ReadLn;
    memo1.lines.add('the time is:' + S);

    IdTCPClient1.IOHandler.WriteInteger(memo1.lines.count); // send the server the count of lines, so it knows how many lines we are about to send it
    for i := 0 to pred(memo1.lines.count) do
      IdTCPClient1.IOHandler.Writeln(Memo1.Lines[i]); // send 1 line at a time

server
====
make an OnExecute event for the TCP Server

procedure TfServerMain.IdTCPServer1Execute(AContext: TIdContext);
var
    s: string;
    i, numlines: integer;
    sl: tstrings;
begin
        AContext.Connection.IOHandler.WriteLn('NAME'); // ask client for name
        S := AContext.Connection.IOHandler.ReadLn;
        if S = 'TIME' then
          AContext.Connection.IOHandler.WriteLn(TimeToStr(Now)'); // send client the time
// now we will receive an integer (# of lines about to be sent) and then 1 line at a time
        sl := TStringList.create;
        try
            numlines := AContext.Connection.IOHandler.ReadInteger;
            for i := 1 to numlines do
              sl.add(AContext.Connection.IOHandler.ReadLn);

// lines from client's memo are in SL
        finally
            sl.free;
        end;
       
end;
 
- something like that anyway :-)
0
 
LVL 2

Expert Comment

by:Mainiacfreakus
ID: 16841237
There are also some examples on the Atozed site:
http://www.atozed.com/indy/Demos/10/index.en.iwp

Look for Zip Code Server(Command Handlers) ; and Zip Code Client (a bit futher down)....


Not related:
(TheRealLoki - have u seen a Indy TCP example that uses user objects and Critical Sections.
I had one, but then my pc broke and had 2 re-format... :\)

Mainiacfreakus
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Screencast - Getting to Know the Pipeline
Suggested Courses
Course of the Month17 days, 1 hour left to enroll

862 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