Solved

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

Posted on 2016-10-18
11
50 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 25

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
 
LVL 25

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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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 25

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 25

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 25

Accepted Solution

by:
Sinisa Vuk earned 500 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
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 …

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now