I am using a TIdTcpServer component to implement a basic server side application. I have clients witch send strings to the server,ascii encoded, ending in these to characters #@.
eg :
this_is_a_sample#@ thisis_another_sample#@
My OnExecute method is the following :
procedure TLX8511.ProcessEvent(AContext: TIdContext);
var
recv : String;
begin
with AContext.Connection.IOHandler do
begin
CheckForDataOnSource(20);
if not InputBufferIsEmpty then
begin
recv := ReadLn('#@');
WriteLn(recv);
end;
end;
end
However when the ReadLn is executed I receive a wierd error : Buffer terminator must be specified
What I am doing wrong ?
LE : I am using Indy with lazarus on linux so this might be some porting issue
Thank you.
I don't like to answer my own questions but based of David Heffernan's suggestion I dug up the problem myself.
Turns out you must specify the encoding in order to avoid that exception so here is the solution:
procedure TLX8511.ProcessEvent(AContext: TIdContext);
var
recv : String;
encoding : IIdTextEncoding;
begin
encoding := IndyTextEncoding_ASCII;
with AContext.Connection.IOHandler do
begin
CheckForDataOnSource(20);
if not InputBufferIsEmpty then
begin
recv := ReadLn('#@',encoding,encoding);
WriteLn(recv);
end;
end;
end;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With