Board index » delphi » Send stream from client to server with Indy

Send stream from client to server with Indy

Hello

I'm new here and need your 'start' help. Please give me tip how to send
stream from client application using TIdTCPClient and read it on server
(using TIdTCPServer) All examples i found use other way (server ->client)
and when I try to transform them I can't find solution.

TIA

Albert

 

Re:Send stream from client to server with Indy


dev...@yahoo.com (Albert) wrote in <3b7a8247_1@dnews>:

Quote
>Hello

>I'm new here and need your 'start' help. Please give me tip how to send
>stream from client application using TIdTCPClient and read it on server
>(using TIdTCPServer) All examples i found use other way (server ->client)
>and when I try to transform them I can't find solution.

It's the same concept but just turned around. If the example you saw is
transfering from the server to the client that means that the server is
issuing a WriteStream. IF you want the client to send to the server then
issue the WriteStream on the client and the ReadStream on the server.

Re:Send stream from client to server with Indy


Quote
"Albert" <dev...@yahoo.com> wrote in message news:3b7a8247_1@dnews...
> Hello

> I'm new here and need your 'start' help. Please give me tip how to send
> stream from client application using TIdTCPClient and read it on server
> (using TIdTCPServer) All examples i found use other way (server ->client)
> and when I try to transform them I can't find solution.

This is so utterly simple that i can not understand why you can not think
this one up for yourself..
Especially as you tell that you have seen this in examples..

Below here a verry simple example...

I suggest you start downloading the help files, and start reading them.

Global Constant:

SendStreamCommand = 'HEY SERVER, WAKE UP, GOING TO SEND YOU A STREAM!';

Client side:

Client.WriteLn(SendStreamCommand);
Client.WriteLn(IntToStr(Stream.Size));
Client.WriteStream(Stream);

Server Side:

For example in server.execute event.

AThread.Connection.ReadLN(Command);
If Command = SendStreamCommand Then
  begin
    AThread.Connection.ReadLN(Size);
    AThread.Connection.ReadStream(Stream,StrToInt(Size));
  end;

I'm assuming here you know how to create and handle streams..

Re:Send stream from client to server with Indy


Quote
> >I'm new here and need your 'start' help. Please give me tip how to send
> >stream from client application using TIdTCPClient and read it on server
> >(using TIdTCPServer) All examples i found use other way (server ->client)
> >and when I try to transform them I can't find solution.

> It's the same concept but just turned around. If the example you saw is
> transfering from the server to the client that means that the server is
> issuing a WriteStream. IF you want the client to send to the server then
> issue the WriteStream on the client and the ReadStream on the server.

I also use this way, but I'm sure something is missing in my source code.
Please let me know what's wrong.

This is my client:
  aStream := TMemoryStream.Create;
  aStream.LoadFromFile('w:\a.sec');
  aStream.Position:=0;
  try
    TCP.Connect;
    TCP.Writeln('SEC');
    TCP.WriteInteger(aStream.Size,true);
    TCP.OpenWriteBuffer;
    TCP.WriteStream(AStream);
    TCP.CloseWriteBuffer;
  finally
    TCP.Disconnect;
  end;
  aStream.Free;

And this my server:
procedure TForm1.TCPExecute(AThread: TIdPeerThread);
begin
  s := uppercase(AThread.Connection.ReadLn);
  if s = 'SEC' then begin
    strLen:=AThread.Connection.ReadInteger(true);
    aStream := TMemoryStream.Create;
    with AThread.Connection do begin
      ReadStream(aStream,strLen,false);
    end;
    aStream.Free;
    AThread.Connection.Disconnect;
  end;
end;

and I get only exception #10053

Thanks

Albert

Re:Send stream from client to server with Indy


Write/Read stream automatically send the size for (by default IIRC). Your
problem might be there.

Re:Send stream from client to server with Indy


You know Arthuro,  its not always so obvious where to go and read about any
particular subject.  I have been delving into Delphi's help files now for a
couple of days and most of their examples don't even work.  Its also strange
that I haven't even been able to find the ReadStream function connected to a
TServerSocket component.

I greatly appreciate your assistance in this matter, but if your going to
get upset with someone not understanding then perhaps you should take a
break.  The number one complaint from any Delphi Programmer has and seems to
always be the lack of information in help files.  I hope to one day be as
smart on this subject as you appear to be, but it will require your
assistance, not your battering...

Thanks,

--
Glenn Hancock
SofTek Software Int'l Inc.
www.softeksoftware.com
ghanc...@softeksoftware.com
770-490-7899

Re:Send stream from client to server with Indy


Arthuro,

I tried you example code and everything seems to have compiled ok, but the
server component is not receiving the command.  I attached the code to the
onconnected property.  Is there somewhere else I should have placed it?

Also, you mentioned downloading and reading the help files to the last
person you were helping on this thread.  What help files were you referring
to and where could I get them, because I would really like to learn more
about these processes...

Thanks,

--
Glenn Hancock
SofTek Software Int'l Inc.
www.softeksoftware.com
ghanc...@softeksoftware.com
770-490-7899

Re:Send stream from client to server with Indy


I also have a question that may be stupid, but I have to ask it.  Handling
these streams in this manor:  Will there be a problem with the server
getting confused and receiving two command sequences from two different
clients, and the processing getting scrambled on the server side?

Thanks,

--
Glenn Hancock
SofTek Software Int'l Inc.
www.softeksoftware.com
ghanc...@softeksoftware.com
770-490-7899

Re:Send stream from client to server with Indy


Quote
"Glenn Hancock" <ghanc...@softeksupport.com> wrote in message

news:3b7be5d8_1@dnews...

Quote
> I also have a question that may be stupid, but I have to ask it.  Handling
> these streams in this manor:  Will there be a problem with the server
> getting confused and receiving two command sequences from two different
> clients, and the processing getting scrambled on the server side?

No. Client connections are in their own thread, whether you're using
OnExecute or CommandHandlers.

Re:Send stream from client to server with Indy


Quote
"Glenn Hancock" <ghanc...@softeksupport.com> wrote in message

news:3b7be49a_2@dnews...

Quote
> Arthuro,

> I tried you example code and everything seems to have compiled ok, but the
> server component is not receiving the command.  I attached the code to the
> onconnected property.  Is there somewhere else I should have placed it?

I suggest you put it in the server's onExecute event.
In one of my older projects i have something that looks like this:
I've put the command/stream handling in a seperate procedure, this is a Pr
Indy 9 project.

With Athread.Connection Do
    Try
      While Connected Do
        Begin
            ....
            HandleCommandsExecute(AThread);
            ....
        End; { Connected }
    Except
      On E:Exception Do
            AddSLog('Unhandled exception: '+E.Message); { Just logging
exceptions to a text file }
    End; { With/ Try }

Quote
> Also, you mentioned downloading and reading the help files to the last
> person you were helping on this thread.  What help files were you
referring
> to and where could I get them, because I would really like to learn more
> about these processes...

I was referring to the INDY help files, they are available for download from
the Indy website:
http://www.nevrona.com/indy
Quote
> Thanks,

> --
> Glenn Hancock
> SofTek Software Int'l Inc.
> www.softeksoftware.com
> ghanc...@softeksoftware.com
> 770-490-7899

Re:Send stream from client to server with Indy


Quote
"Glenn Hancock" <ghanc...@softeksupport.com> wrote in message

news:3b7bd7c0_1@dnews...

Quote
> You know Arthuro,  its not always so obvious where to go and read about
any
> particular subject.  I have been delving into Delphi's help files now for
a
> couple of days and most of their examples don't even work.  Its also
strange
> that I haven't even been able to find the ReadStream function connected to
a
> TServerSocket component.

Since you were talking about the Indy TidTCPServer component, and were
talking about having seen the examples, i know it should be rather simple to
come to the conclusion on how to do it.
I don't know anything about Delphi's TServerSocket, i've never understood
it, also never taken the time to look up how it works in depth. I suppose
they don't support streaming if you say you can't find the readstream
function. But you were talking about INDY components, so you're looking at
the wrong place for information..

 > I greatly appreciate your assistance in this matter, but if your going to

Quote
> get upset with someone not understanding then perhaps you should take a
> break.

Not upset, amazed that you can't convert an examle that is as simple as

server-> WriteStream
Client-> ReadStream

Into

Client-> WriteStream
Server-> ReadStream

(This is of course an over simplified example!).

Quote
> The number one complaint from any Delphi Programmer has and seems to
> always be the lack of information in help files.

While the Indy help files are not the pinnacle of beauty, they're helpfull
enough to have figured that one out.
From what you mentioned above i gather that you were looking at the wrong
help instructions..

Quote
>I hope to one day be as smart on this subject as you appear to be, but it
will require your
> assistance, not your battering...

As i tried with giving you an example of how i'd do it.. I've done this a
few times..

Programming with Indy components is really verry simple, you have to set
your mind to thinking simple.
It also helps verry much if you read Chad's articles on programming and
Indy..
Those are available through the indy website at: http://www.nevrona.com/indy

Regards,
Marco, aka Arthuro..

Re:Send stream from client to server with Indy


Thanks,  I had already figured it out after finding and reading the
articles.  You really should remember that just because someone doesn't
understand something as well as you do, doesn't make us dumb.  I am sure you
a great guy, but you come across as being very rude in your comments...

If everyone responded the way you do, newsgroups would hardly be used at
all.

Thanks anyway,

--
Glenn Hancock
SofTek Software Int'l Inc.
www.softeksoftware.com
ghanc...@softeksoftware.com
770-490-7899

Other Threads