TCPReceive
From SCAR Divi Manual
(Redirected from ReadConnectionData)
Definition
function TCPReceive(const iTCPClient: Integer; var s: string): Boolean;
Availability
SCAR Divi 3.26 > Current
- Before SCAR Divi 3.25 the function would wait for incoming data indefinitely.
Aliases
- ReadConnectionData (SCAR Divi 3.00 > Current)
Description
Receives data from a TCP connection associated with the index iTCPClient in the TCP client resource manager. The resulting string is returned in s. The read timeout is set to 1000ms, if no data is received before then, s will return an empty string. If s is not empty, the function will return true.
Example
var
i: Integer;
Nick, s: string;
Running: Boolean;
begin
Running := True;
Nick := 'Test' + IntToStr(Random(999));
i := TCPConnect('irc.scar-divi.com', 6667, 1000);
try
TCPSend(i, 'NICK ' + Nick);
TCPSend(i, 'USER ' + Nick + ' 0 * :' + Nick);
TCPSend(i, 'JOIN #scar');
while Running do
begin
TCPReceive(i, s);
if s = '' then
Wait(500)
else
WriteLn(s);
if Pos('= #scar', s) > 0 then
begin
TCPSend(i, 'PRIVMSG #scar :Hello World!');
Running := False;
end;
end;
finally
TCPFree(i);
end;
end.