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
dolphin KingAsked:
Who is Participating?
 
Sinisa VukCommented:
This components are thread safe if you set Multithreaded to true (look my new example...).
In new example I show how to mix sending file stream with send text command...
When server (RCVFILE) receive command from one of clients (start more instance of SENDFILE) - data is repost to all other clients using separate thread. More or less - all is event driven... so easy to use when realize what is behind.
test_send_file2.zip
0
 
Sinisa VukCommented:
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...
0
 
dolphin KingAuthor Commented:
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
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
dolphin KingAuthor Commented:
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
0
 
Sinisa VukCommented:
Ok, will try to make some - but will take a time...
0
 
dolphin KingAuthor Commented:
thank you i will be waiting
0
 
dolphin KingAuthor Commented:
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
0
 
Sinisa VukCommented:
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
0
 
dolphin KingAuthor Commented:
i cannot send direct memorystream  with this component ?
0
 
Sinisa VukCommented:
No, it is more low level...but is very flexible...Instead of filestream - you could use memorystream...
0
 
dolphin KingAuthor Commented:
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

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.