Newsgroups : Borland : borland.public.delphi.internet.winsock : 2007 Feb : Re: UDPServer freezes (AntiFreeze doens't help much)
| Subject: | Re: UDPServer freezes (AntiFreeze doens't help much) |
| Posted by: | "Remy Lebeau (TeamB)" (no.spam@no.spam.com) |
| Date: | Mon, 5 Feb 2007 18:14:07 |
"Samu" <samuel.lopez@telefonica.net> wrote in message
news:45c79480$1@newsgroups.borland.com...
> procedure TForm1.serviUDPRead(Sender: TObject; AData: TStream;
> ABinding: TIdSocketHandle);
<snip>
No wonder your code is not working. You are approaching the issue
from the completely wrong direction. You need to use the event
handler's AData parameter instead. It contains the inbound data that
the server received prior to then triggering the OnUDPRead event.
That is where you need to get your data from instead of calling
ReceiveString(). For example:
procedure TForm1.serviUDPRead(Sender: TObject; AData: TStream;
ABinding: TIdSocketHandle);
var
x, y, dat: String;
begin
SetLength(dat, AData.Size);
if AData.Size > 0 then AData.ReadBuffer(data[1], AData.Size);
if dat = '!' then
begin
dib.Canvas.Rectangle(-50, -50, 900, 900);
Exit;
end;
if dat = '&' then
begin
ta := True;
Exit;
end;
x := dat.SubString(1, 3);
y := dat.SubString(5, 3);
if ta then
begin
dib.Canvas.MoveTo(StrToInt(x), StrToInt(y));
ta := False;
end else
dib.Canvas.LineTo(StrToInt(x), StrToInt(y));
end;
Gambit