Newsgroups : Borland : borland.public.delphi.internet.winsock : 2006 Mar : Re: SendBuf - how to do with tmemorystream
| Subject: | Re: SendBuf - how to do with tmemorystream |
| Posted by: | "Angela Bodnar" (angela.bodn..@noris.org) |
| Date: | 1 Aug 2006 08:41:27 |
Hello,
I have a app that currently uses SendStream or SendText from
a ClientSocket.socket. I want to change it to use SendBuf
because it clogs up after I try to send something too large
and I need to start sending images anyway.
I like your sample code here, but how do I use the SendBuf
function with a TMemoryStream? Also, I do not have the option
of disconnecting the socket on failure because it must stay
up all the time since it sends and receieves asyncronously
continually.
Thanks,
Angela
"Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> wrote:
>
>"Ivan Kossey" <spamers.sollen.sterben@cablenet.de> wrote in message
>news:4422d0b1@newsgroups.borland.com...
>
>> It is not mentioned
>> 1. What is the type of buf (PChar, string,...)?
>
>Actually, it does. It is an untyped parameter, analagous to a Pointer.
>Which means that you can pass anything to it that represents a memory
>address.
>
>> 2. What integer value returns the function?
>
>It returns how many bytes were actually accepted. It can be less then the
>amount specified by the bufsize parameter, if there is not enough room for
>the entire buffer. If the the return value indicates that not all of the
>buffer was sent, then you have to adjust your input pointer accordingly and
>call SendBuf() again to sent the remaining data.
>
>Here are a few examples:
>
> var
> buffer: array[0..11] of Byte;
> idx, sent: Integer;
> begin
> // fill the buffer as needed ...
> idx := 0;
> while idx < SizeOf(buffer) do
> begin
> sent := ...SendBuf(buffer[idx], SizeOf(buffer)-idx);
> if sent = -1 then begin // blocking send, resend
> Sleep(50);
> Continue;
> end;
> if sent = 0 then Break; // disconnected
> Inc(idx, sent);
> end;
> end;
>
>
> var
> buffer: array of Byte;
> idx, sent: Integer;
> begin
> SetLength(buffer, 12);
> // fill the buffer as needed ...
> idx := 0;
> while idx < Length(buffer) do
> begin
> sent := ...SendBuf(buffer[idx], Length(buffer)-idx);
> if sent = -1 then begin // blocking send, resend
> Sleep(50);
> Continue;
> end;
> if sent = 0 then Break; // disconnected
> Inc(idx, sent);
> end;
> end;
>
>
> var
> s: String;
> idx, sent: Integer;
> begin
> s := 'something';
> idx := 0;
> while idx < Length(s) do
> begin
> sent := ...SendBuf(PChar(s)+idx, Length(s)-idx);
> if sent = -1 then begin // blocking send, resend
> Sleep(50);
> Continue;
> end;
> if sent = 0 then Break; // disconnected
> Inc(idx, sent);
> end;
> end;
>
>
> var
> value: Integer;
> ptr: PByte;
> idx, sent: Integer;
> begin
> value := 12345;
> idx := 0;
> while idx < SizeOf(i) do
> begin
> sent := ...SendBuf(PByte(@value)[idx], SizeOf(value)-idx);
> if sent = -1 then begin // blocking send, resend
> Sleep(50);
> Continue;
> end;
> if sent = 0 then Break; // disconnected
> Inc(idx, sent);
> end;
> end;
>
>
>Gambit