Not sure I understand well.
Seems you are sending many strings but you receive in only one. Is it
correct ?

> li_rec    := Receive (@Buffer, SizeOf(Buffer));

You have to check for li_rec > 0 before handling anything.
Another point: Be sure to avoid Application.ProcessMessages (or any other
message pump form) in your application. At least from any ICS event. Using
ProcessMessages has very bad effect on event handling (All events, even
simple TButton.OnClick, but specially high rate hardware generated events
such as network I/O).

Side not: You code is difficult to read. I suggest you use ICS coding style.

Contribute to the SSL Effort. Visit
Author of ICS (Internet Component Suite, freeware)
Author of MidWare (Multi-tier framework, freeware)

----- Original Message ----- 
From: "Thomasius, Michael" <[EMAIL PROTECTED]>
To: <>
Sent: Wednesday, June 14, 2006 1:57 PM
Subject: [twsocket] Sending with SendStr loses packets

> Hallo,
> I am using the ICS now for a long time, but there is one problem which I
wasn't able to solve.
> Now I hope there is somebody outside, who can give me "illumination" ;-).
I try to explain this very detailled, sorry for the large mail.
> I send many messages via SendStr. They can be very large (about 100KB
> At first my implementation:
> I use a method called SendNext:
> procedure Tnvc_AsyncBufferedClientSocket.SendNext;
> begin
> IF (osl_SendMessages.Count > oi_nextsend) THEN BEGIN
>    IF NOT ob_sending THEN BEGIN
>       ob_sending := TRUE;
>       oSock_Client.SendStr (osl_SendMessages.Strings[oi_nextsend]);
> inc (oi_nextsend);
>    END {IF};
>    ob_sending := FALSE;
> {END {IF};
> end;
> In the event OnDataSent I do the following:
> procedure Tnvc_AsyncBufferedClientSocket.Socket_OnDataSent(Sender:
TObject; ErrCode: Word);
> begin
> ob_sending := FALSE;
> SendNext;
> end;
> On the receiving side I use the DataAvailable event looking like this
> procedure
TObject; Error : Word);
> VAR   Buffer : array [0..4096] of char;
> ls_receive, ls_msg:String;
>       li_rec:Integer;
>       li_msglen:Integer;
> begin
> li_rec    := Receive (@Buffer, SizeOf(Buffer));
> os_newMessage := copy (buffer,1, li_rec);
> oi_len := oi_len + Length (os_newMessage);
> os_Message := os_Message + os_newMessage;
> //Process os_message
> end;
> Now the problem:
> If I am using this in a local network everything works fine. That means
all data which was sent will be received.
> If I use this over the internet I lose many packets. And I don't know why.
> As I thought the SendStr-procedure works with an internal buffer, which
guarantees that all messages which were sent will be received right on the
other side?
> In an other implementation I do a "SendBlock". that means, I divide my
Message in tcp-Blocks (around 1400 Bytes per Block) and wait for an
OnDataSent after each block. This seems to work without losses.
> The problem is, that I need to have the sending asyncron, means the
application has to handle incoming messages during sending, so I must
implement my own thread handling - this I would like to avoid.
> I know, the description is a little bit confused, but I hope you
understand my problem and maybe you have own experiences how to implement a
tcp-send/receive where it is guaranteed that all messages which are sent
will be received.
> Thanks for any hints,
> M;chael
> -- 
> To unsubscribe or change your settings for TWSocket mailing list
> please goto
> Visit our website at

To unsubscribe or change your settings for TWSocket mailing list
please goto
Visit our website at

Reply via email to