Link to home
Start Free TrialLog in
Avatar of dolphin King
dolphin King

asked on

how to send memory stream from ics Client To ics server ?

i have been using indy for a while but i want to test the ics component i will use Twsocket . in indy its very easy to send memory stream from client to server or from server to client as example i have been doing something like this in the client side

procedure TClient.SendBuffer(Buffer: TIdBytes; BufferSize: Cardinal);
Var
Strm: TIdMemoryBufferStream;
begin
ClientThread.Lock;
try
if not idtcp.Connected then
begin
exit;
end;

Strm := TIdMemoryBufferStream.Create(PByte(Buffer), BufferSize);
try
FTCP.Socket.WriteLn('streamcmd');
FTCP.Socket.LargeStream := True;
FTCP.Socket.Write(Strm, 0, True);
finally
Strm.Free;
end;
finally
ClientThread.Unlock;
end;
end;

Open in new window


and on the server side i have been receive the stream like this as example on server execute

      MS := TMemoryStream.Create;
      AContext.Connection.Socket.LargeStream := true;
      AContext.Connection.Socket.ReadStream(MS, -1, False);
      MS.Position := 0;

Open in new window


how can i convert my code to ics and send and receive stream i have looked at there demo specially FTP demo but i am getting lost it will be helpful if there is code example applied to my code
Avatar of Sinisa Vuk
Sinisa Vuk
Flag of Croatia image

Go to ICS user page and locate sendfile(.zip) sample project... This is file sending example - but file is nothing more than a stream... There are other useful examples too...
Avatar of dolphin King
dolphin King

ASKER

i have been told many times to check the ics example and i mention that in the question , i checked there sendfile of the FTP sample and i couldn't understand any clear behavior on send any stream it would be  helpful if i see small clear example that simply applied at my posted code

for example send that stream from Client protocol  / server on data available receive that stream
i checked the send file project demo again i have no idea how to send the memorystream the protocol that i am trying to do is

if command = text then
send text to clients else
if command = memorystream then
send send memorystream to all clients

and so on would be nice if see simple client and server that do this approach
Ok, will try to make some - but will take a time...
thank you i will be waiting
i really needed this example i am tired from indy too Manny issues , i just wanted to convert my indy server to ics

with a brief of creating server class that hold name and IP-address  and protocol to send commands and memory stream in thread safe manner , searched every where did not found clear example
Ok, here is my example project (sender and receiver)...
It is build upon sendfile(.zip) sample which I suggest in first post...
Client use OnDataSent event to send file data packets...block by block. Clint first send header with a file name, and then data. Each block have own Block header with data type  (text, filename, file data,...), Server use OnDataAvailable event where for each client check block type (text, filename, file data,...) and act depending on it...Hope it helps...
test_send_file.zip
i cannot send direct memorystream  with this component ?
No, it is more low level...but is very flexible...Instead of filestream - you could use memorystream...
is this component is thread safe ? can you provide a synchronized sample  with this component ? also i cannot figure how can i handle multiable commands

what if the command sended should be string

as example

 if command = 'text' then begin
send text to each client on server
end else if command = ''
then 
begin
send memory stream to each client on server
end;

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Sinisa Vuk
Sinisa Vuk
Flag of Croatia image

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