Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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

Posted on 2016-10-18
11
Medium Priority
?
414 Views
Last Modified: 2016-11-07
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
0
Comment
Question by:dolphin King
  • 6
  • 5
11 Comments
 
LVL 28

Expert Comment

by:Sinisa Vuk
ID: 41849924
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
 

Author Comment

by:dolphin King
ID: 41850501
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
 

Author Comment

by:dolphin King
ID: 41859605
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
Industry Leaders: 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!

 
LVL 28

Expert Comment

by:Sinisa Vuk
ID: 41859758
Ok, will try to make some - but will take a time...
0
 

Author Comment

by:dolphin King
ID: 41861161
thank you i will be waiting
0
 

Author Comment

by:dolphin King
ID: 41873406
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
 
LVL 28

Expert Comment

by:Sinisa Vuk
ID: 41873569
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
 

Author Comment

by:dolphin King
ID: 41874262
i cannot send direct memorystream  with this component ?
0
 
LVL 28

Expert Comment

by:Sinisa Vuk
ID: 41876425
No, it is more low level...but is very flexible...Instead of filestream - you could use memorystream...
0
 

Author Comment

by:dolphin King
ID: 41876473
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
 
LVL 28

Accepted Solution

by:
Sinisa Vuk earned 2000 total points
ID: 41877120
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

Featured Post

Industry Leaders: 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 will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Introduction to Processes

571 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