3

TIdTcpServer コンポーネントを使用して、基本的なサーバー側アプリケーションを実装しています。私はクライアントにサーバーに文字列を送信させ、ascii エンコードし、文字 #@ で終わります。

例:

this_is_a_sample#@ thisis_another_sample#@

私の OnExecute メソッドは次のとおりです。

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

ただし、ReadLn が実行されると、奇妙なエラーが表示されます。バッファ ターミネータを指定する必要があります。

私が間違っていることは何ですか?

LE : Linux で Indy と lazarus を使用しているので、これは移植の問題である可能性があります。

ありがとうございました。

4

1 に答える 1

3

私は自分の質問に答えるのは好きではありませんが、David Heffernan の提案に基づいて、自分で問題を掘り下げました。

その例外を回避するためにエンコーディングを指定する必要があることが判明したので、ここに解決策があります:

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;  
于 2013-08-05T10:38:58.230 に答える