흐르는 시간의 블로그...

출처 :http://stackoverflow.com/questions/544204/delphi-2009-indy-10-tidtcpserver-onexecute-how-to-grab-all-the-bytes-in-the-i

델파이에서 인디 컴포넌트인 TIdTCPServer를 사용하는 방법 샘플코드

아래의 예제는 받은대로 보내주는 것임.
OnExecute는 계속 실행되는 함수이다.


procedure TForm1.IdTCPServer1Execute(AContext: TIdContext);
var
RxBufStr: String; // not UTF8String
begin
with AContext.Connection.IOHandler do
begin
if not InputBufferIsEmpty then
begin
CheckForDataOnSource(10);
// RxBufStr := InputBuffer.Extract(-1, enUtf8);
RxBufStr := InputBuffer.Extract;
WriteLn(RxBufStr);

with Application do
begin
MessageBox(PChar(RxBufStr), 'Look', MB_OK); // [smbOK]
end;
end;
end;

// Alternatively to above, you can set the
// InputBuffer.Encoding property to enUtf8
// beforehand, and then call TIdBuffer.Extract()
// without any parameters.
//
// Or, set the IOHandler.DefStringEncoding
// property to enUtf8 beforehand, and then
// call TIdIOHandler.InputBufferAsString()

// process RxBufStr as needed...
end;