在国外论坛看到一段关于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);
分享到:
相关推荐
Table buffering in SAP
mfc double buffering tech. reduce screen flicker.
AB PLC例程_本资料仅供学习参考
图文并茂地讲述了图形显示double buffering、vsync信号和triple buffering的机理。
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 ...
Table buffering in SAP
note:504875 - Buffering number ranges 1
主要介绍了浅谈PHP中output_buffering的相关资料,需要的朋友可以参考下
A double buffer example by Klaas Holwerda.This does the buffering 'manually', it seems.
打开了php输出缓存: echo,print -> php output_buffring -> server buffering -> browser buffering -> browser display2.未打开php输出缓存: echo,print -> server buffering -> browser buffering -> browser ...
主要介绍了PHP中的output_buffering详细介绍,本文讲解了output buffering的一些高级用法,需要的朋友可以参考下
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 ...
Boost Up Carrier Mobility for Ferroelectric Organic Transistor Memory via Buffering Interfacial Polarization Fluctuation.
本篇文章是对php缓冲output_buffering进行了详细的分析介绍,需要的朋友参考下
开源项目-zieckey-go-doublebuffering.zip,一个简单的库,用于管理可适当升级的资源
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-...
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...
主要介绍了php缓冲 output_buffering和ob_start的相关资料,需要的朋友可以参考下