• Transfering Stream Data using Remote Functions


    Author Transfering Stream Data using Remote Functions
    Danijel Tkalcec [RTC]

    01.06.2006 21:17:27
    Registered user
    You can send streams with remote functions (limited length, since all data has to be kept in memory while sending and receiving) by using newByteStream to create the in-memory Stream, then using asByteStream (this is a TMemoryStream) to read/write data from the stream.

    If you have components which write to a memory stream, you can pass “asByteSteam” as a parameter to those components methods/functions, so they can directly fill their content into the stream. On the other side, when the stream arrives, you can use “asByteStream” to access the data received.

    Here are some examples …

    EXAMPLE 1: Send a stream from a client to the server as a parameter in a remote function call …

    On the client-side, to call the remote function, passing the stream as a parameter:
    with myClientModule do
      begin
      with Data.newFunction(’callme’) do
        begin
        newByteStream(’mydata’);
        Some_Function_which_fills_the_stream(asByteStream[’mydata’]);
        end;
      Call(myResult);
      end;

    And on the server side (OnExecute event), you can access all data inside your stream like this:
    // need to make sure this parameter is a ByteStream …
    if isType[’mydata’]=rtc_ByteStream then
      Some_Function_which_reads_from_stream(asByteStream[’mydata’]);

    EXAMPLE 2: Send a stream as a result of a function call from the Server to the Client.

    In server’s OnExecute event, create the stream and fill it with data:
    Result.newByteStream;
    Some_Function_which_fills_the_stream(Result.asByteStream);

    And on the Client side (OnReturn event), you can access all data inside your stream like this:
    // need to make sure this parameter is a ByteStream …
    if Result.isType=rtc_ByteStream then
      Some_Function_which_reads_from_stream(Result.asByteStream);

    EXAMPLE 3: Send a stream from Server’s OnExecute event as a result of a remote function call, now packed inside a record, so you can supply more information about data in that stream.

    On the Server-side, you can write something like this:
    with Result.newRecord do
      begin
      newByteStream(’mydata’);
      Some_Function_which_fills_the_stream(asByteStream[’mydata’]);
      end;

    And on the Client side (OnReturn event), you can access all data inside your stream like this:
    // need to make sure this parameter is a Record …
    if Result.isType=rtc_Record then
      with Result.asRecord do
        begin
        // need to make sure this parameter is a ByteStream …
        if isType[’mydata’]=rtc_ByteStream then
          Some_Function_which_reads_from_stream(asByteStream[’mydata’]);
        end;
  • 相关阅读:
    【Vue】详解Vue生命周期
    千万不要用window自带文本编辑器编辑配置文件或者代码
    [其它]iOS 13 正式版发布 iPhone 6s或更新型号均可升级
    [转]解决ubuntu16.04 ‘E: 无法获得锁 /var/lib/dpkg/lock-frontend
    [golang]使用gomail发邮件(在Go中发送电子邮件的最佳方式)
    [golang]按图片中心旋转后的新图左顶点和原图左顶点的偏移量计算
    分布式CAP定理,为什么不能同时满足三个特性?
    Java如何运行一个class文件的main方法
    数据库的四大特性以及四个隔离级别和引发的问题
    Redis为什么可以支持那么大的并发访问量?为什么redis没有单点并发瓶颈?
  • 原文地址:https://www.cnblogs.com/liangchua/p/6594639.html
Copyright © 2020-2023  润新知