Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

Posted on 2016-10-18
11
137 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 26

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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 26

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 26

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 26

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 26

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?

828 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