`
cloud21
  • 浏览: 396317 次
  • 性别: Icon_minigender_2
  • 来自: 北京
社区版块
存档分类
最新评论

Buffering example for Indy 10

阅读更多
在国外论坛看到一段关于Indy 10 操作Buffer的文章,记录下。

CLIENT (Delphi)

{ vBufferIn: TIdBytes; }
{ vBufferOut: TIdBytes; }

        { Set the length of the buffer for the request }
        SetLength(vBufferIn,length(pInputXML));
        StringSize := Length(pInputXML);
        { Load the bytes array }
        for i := 0 to StringSize - 1 do
        begin
          vBufferIn[i] := Byte(pInputXML[i+1]);
        end;
        { Send the request }
        FSocket.IOHandler.Write(vBufferIn);

        BufferSize := 0;
        TotalBufferSize := 0;
        { Set the length as zero means set as dynamic and leaving
          Indy to work with the size of the array. }
        SetLength(vBufferOut,0);
        { Loop while the socket is connected }
        while (FSocket.Connected) do
        begin
          { fill the output buffer with a timeout of 10 ms }
          FSocket.IOHandler.CheckForDataOnSource(10);
          { Returns true if the output buffer is currently empty }
          if not (FSocket.IOHandler.InputBufferIsEmpty) then
          begin
            { get the size of the output buffer }
            BufferSize := FSocket.IOHandler.InputBuffer.Size;
            { save the size of the output buffer and add it to the total for the array }
            TotalBufferSize := TotalBufferSize + BufferSize;
            { read the output buffer and save it into the array }
            { N.B the last parameter is very important is the AAppend and if you
            set as true means the buffer is added at the end otherwise if set to false
            the buffer cover the array from the begin. }
            FSocket.IOHandler.ReadBytes(vBufferOut, BufferSize, true);
          end;
        end;
        { moves the byte array into the string }
        pOutPutXML := BytesToString(vBufferOut, 0, TotalBufferSize);

+------------------------------------------------------------+

CLIENT (C#) (don't care about base64 this is only because this client is a web service and the SOAP
envelope consumed by a WIN32 client SOAP had encoding problems.)

    Byte[] RecvBytes = new Byte[0];
    Byte[] OutRecvBytes = new Byte[0];
            
            
    // Decode the input into a bytes array converting the string
    // representation of a value of base 64 digits to an equivalent
    // array of 8-bit unsigned integers
    RecvBytes = System.Convert.FromBase64String(InputXML);
    // Send the request
    mySocket.IOHandler.Write(RecvBytes);
    // Receive response
    int BufferSize = 0;        
    // Loop until the socket is connected
    while (mySocket.Connected())
    {
        // fill the input buffer with a timeout of 10 ms
        mySocket.IOHandler.CheckForDataOnSource(10);
        // Returns true if the input buffer is currently empty
        if (! mySocket.IOHandler.InputBufferIsEmpty())
        {
            // get the size of the input buffer
            BufferSize = mySocket.IOHandler.InputBuffer.Size;
            // Read the input buffer and save it into the array
            // N.B the last parameter is very important is the AAppend and if you
            // set as true means the buffer is added at the end otherwise if set to false
            // the buffer cover the array from the begin
            mySocket.IOHandler.ReadBytes(ref OutRecvBytes, BufferSize, true);
        } // end if
    } // end while (mySocket.Connected())
    // Converts the value of an array of 8-bit unsigned integers to equivalent String
    // representation consisting of base 64 digits.
    OutputXML = System.Convert.ToBase64String(OutRecvBytes,0,OutRecvBytes.Length);

+------------------------------------------------------------+

SERVER CONNECTION

      { vBuffer: TIdBytes; }    
      { vInputData: WideString }

      { Get the data }
      BufferSize := 0;
      TotalBufferSize := 0;
      { We must wait for a request }
      { Setting the length as zero means set as dynamic and leaving
        Indy to work with the size of the array. }
      SetLength(vBuffer,0);
      { fill the input buffer with a timeout of 10 ms }
      vTET.Connection.IOHandler.CheckForDataOnSource(10);
      { loop until the input buffer is empty }
      repeat
        { Returns true if the input buffer is currently empty }
        if not (vTET.Connection.IOHandler.InputBufferIsEmpty()) then
        begin
          { get the size of the input buffer }
          BufferSize := vTET.Connection.IOHandler.InputBuffer.Size;
          { save the size of the input buffer and add it to the total for the array }
          TotalBufferSize := TotalBufferSize + BufferSize;
          { read the input buffer and save it into the array }
          { N.B the last parameter is very important is the AAppend and if you
          set as true means the buffer is added at the end otherwise if set to false
          the buffer cover the array from the begin. }
          vTET.Connection.IOHandler.ReadBytes(vBuffer, BufferSize, true);
        end;
        vTET.Connection.IOHandler.CheckForDataOnSource(10);
      until (vTET.Connection.IOHandler.InputBufferIsEmpty());
      { moves the byte array into the string }
      vInputData := BytesToString(vBuffer, 0, TotalBufferSize);

+------------------------------------------------------------+

SERVER EXECUTE

      { vBuffer: TIdBytes; }    
      { vOutputXML: WideString }

      { Send the data }
      SetLength(vBuffer,length(vOutputXML));
      for i := 0 to length(vOutputXML) -1 do
      begin
        vBuffer[i] := Byte(vOutputXML[i+1]);
      end;
      IOHandler.Write(vBuffer);

0
0
分享到:
评论

相关推荐

    [MMS_042496]Data Buffering and Handshaking example.rar

    "[MMS_042496]Data Buffering and Handshaking example"很可能包含了一个实际的AB PLC程序,展示了如何在实际应用中设置和使用数据缓冲和握手协议。这个例子可能会涵盖如何配置缓冲区大小、何时启用和禁用握手协议...

    Table buffering in SAP

    ### SAP中的表缓冲 #### 为什么在R/3中使用表缓冲? 在SAP R/3系统中,表缓冲技术是一种提高数据访问速度的关键方法。它通过将数据库表的部分或全部内容缓存到内存中来减少对物理磁盘的访问次数,从而显著提升应用...

    double buffering

    在计算机图形学和GUI编程中,"double buffering"(双缓冲)是一种重要的技术,用于减少屏幕闪烁现象,提高用户体验。尤其是在使用Microsoft Foundation Classes (MFC)库进行Windows应用程序开发时,双缓冲是解决界面...

    16Edit 16进制编辑源代码 传奇人物yoda出品

    Chris Hobbs - for his back-buffering example on Icz's side KS - for some beta testing schieber - for letting me do tests on ur WinXP machine Dave P. - you know why Baader - for all the compression ...

    浅谈PHP中output_buffering

    服务器端缓存又可以细分为程序缓存和OB缓存(即Output Buffering,输出缓冲)。当`output_buffering`开启时,PHP会先将输出的内容存储在内存中,直到达到一定的阈值或脚本结束时才一次性发送给浏览器。未开启时,PHP...

    PHP中的output_buffering详细介绍

    理解output_buffering的工作原理及其高级用法对于开发稳定和高效的Web应用程序至关重要。本文将详细介绍output_buffering的概念、功能及其如何帮助开发者处理HTTP响应头和主体,并探讨其高级用法。 首先,了解Web...

    php缓冲 output_buffering的使用详解

    `output_buffering`配置选项控制这一行为。 首先,理解缓冲(buffer)的概念是至关重要的。在计算机系统中,缓冲区是一种临时存储区域,用于在不同速度或优先级的硬件之间存储和转发数据。在PHP中,输出缓冲是指在...

    504875 - Buffering number ranges

    1. 主内存缓冲(Main Memory Buffering) 主内存缓冲适用于数字分配没有法律要求的场景,也就是说,在不涉及到法律规定必须按顺序分配数字的场合下可以使用。通过SAP事务码SM56可以查看主内存缓冲的内容。使用这种...

    What are Double Buffering, vsync and Triple Buffering

    双缓冲、垂直同步(Vsync)和三重缓冲是计算机图形学中用于改善显示器输出流畅性和视觉质量的关键技术。在早期的计算机系统中,只使用单缓冲机制,导致画面更新时经常出现闪烁现象,严重影响用户体验。...

    php缓冲 output_buffering和ob_start使用介绍

    反之,当output_buffering被设置为0,即禁用了输出缓冲时,每次执行输出操作,数据会立即发送到浏览器,用户可以看到脚本逐步执行的结果。这适用于需要即时反馈给用户的场景,但可能会导致页面渲染不够流畅。 文章...

    基于PHP输出缓存(output_buffering)的深入理解

    在此配置下(`output_buffering=4096`, `implicit_flush=Off`),`for`循环中的每一项输出都会先被`ob_flush()`移动到服务器缓冲区,然后通过`flush()`发送到浏览器,即使它们小于浏览器的缓存大小。这种做法在需要...

    DIZipWriter v6.2.0 for D7-XE10.1 ZIP 压缩 解压缩

    DIZipWriter outputs all data to the archive straight away, with no need for temporary storage: It does not create any temporary files and does not use huge amount of memory for buffering. It is ...

    开源项目-zieckey-go-doublebuffering.zip

    开源项目“zieckey-go-doublebuffering”是一个基于Go语言实现的库,专注于提供高效、优化的资源管理机制,特别是针对需要频繁更新的资源。在软件开发中,尤其是在图形界面或者高并发环境下,双缓冲技术是一种常用的...

    Writing GNOME Applications

    Double Buffering with a Pixmap 10-4. RGB Row Strides 10-5. Array of ArtVpath Elements 10-6. Vector Paths of the Letters V and R 10-7. Microtile Arrays 10-8. Rendering an Alpha Channel to a Bitmap 10-...

    Geo数据的数据 caching 和数据 buffering 如何实现解决方案(亲测可用).md

    Geo数据的数据 caching 和数据 buffering 如何实现解决方案(亲测可用).md

    Graphics32 for XE2

    Flicker-free image displaying components with optimized double buffering via advanced MicroTiles? based repaint optimizer; Multiple customizible easy-to-use overlay layers; Locking of bitmaps for safe...

    SAP table buffering

    - **访问速度快**:对SAP缓冲区的访问通常比直接访问数据库快10到100倍。 - **减少数据库负载**:随着系统的增长,减少数据库访问尤为重要。 **2. 表缓冲的种类** 对于ABAP字典中定义的每个表,可以决定是否启用...

    DESIGN FOR EMBEDDED IMAGE PROCESSING ON FPGAS

    4.5 Designing for Tuning and Debugging 102 4.5.1 Algorithm Tuning 102 4.5.2 System Debugging 104 5 Mapping Techniques 107 5.1 Timing Constraints 107 5.1.1 Low Level Pipelining 107 5.1.2 Process ...

Global site tag (gtag.js) - Google Analytics