Registriert seit: 25. Sep 2004
79 Beiträge
Delphi XE7 Professional
|
AW: Indy TCP Client/Server
30. Mär 2012, 10:20
Hier ein kleines Demo-Projekt, um das Ganze zu demonstrieren.
Versand:
Delphi-Quellcode:
var
I : Integer;
Data : TBytes;
begin
Send.Enabled := False;
Application.ProcessMessages;
for I := 1 to 10000 do
begin
SetLength(Data, SizeOf(Integer));
Move(PByte(I), Data[0], SizeOf(Integer));
FClient.IOHandler.Write(LongInt(Length(Data)));
FClient.IOHandler.Write(Data);
end;
end;
Empfang:
Delphi-Quellcode:
var
DataSize : LongInt;
Data : TBytes;
Value : Integer;
begin
if AContext.Connection.IOHandler.Readable then
begin
DataSize := AContext.Connection.IOHandler.ReadLongInt;
AContext.Connection.IOHandler.ReadBytes(Data, DataSize);
Value := 0;
Move(Data[0], PByte(Value), SizeOf(Integer));
TThread.Queue
(
TThread.CurrentThread,
procedure
begin
UI.Caption := IntToStr(Value);
end
);
end;
end;
|
|
Zitat
|