SendCmd()
はあなたのために、サーバからの応答を読み込み、そのサーバーは、実際には2つの別々の応答を送信しない限り、SendCmd()
後GetResponse()
を呼び出さないでください。
応答は、通常の形式をとります。
<Response Code> <Optional Text>
応答コード番号またはテキストのキーワードのいずれかである
。
サーバは、数値応答コードを送信した場合、このようにそれを扱う:
サーバー:
// sends:
//
// 200 1
//
ASender.Reply.SetReply(200, '1');
クライアント:
if TCPclient.SendCmd(theMessage) = 200 then
Value := StrToInt(TCPclient.LastCmdResult.Text.Text);
または:
// raises an exception if a non-200 response is received
TCPclient.SendCmd(theMessage, 200);
Value := StrToInt(TCPclient.LastCmdResult.Text.Text);
の場合サーバーから送信されます
サーバー:
// sends:
//
// OK 1
//
ASender.Reply.SetReply('OK', '1');
クライアント:
if TCPclient.SendCmd(theMessage, '') = 'OK' then
Value := StrToInt(TCPclient.LastCmdResult.Text.Text);
または:xtual応答コードは、このようにそれを扱う
// raises an exception if a non-OK response is received
TCPclient.SendCmd(theMessage, ['OK']);
Value := StrToInt(TCPclient.LastCmdResult.Text.Text);
応答のオプションのテキスト、存在する場合、 プロパティでアクセスできます。可能であればTStrings
ですフォームで複数行の応答を送信します
<Response Code>-<Optional Text>
<Response Code>-<Optional Text>
...
<Response Code> <Optional Text>
サーバー:
// sends:
//
// 200-The value is
// 200 1
//
ASender.Reply.SetReply(200, 'The value is');
ASender.Reply.Text.Add('1');
クライアント:
TCPclient.SendCmd(theMessage, 200);
Value := StrToInt(TCPclient.LastCmdResult.Text[1]);
ます。また、この形式で回答した後、二次複数行のテキストを送信することができます:
<Response Code> <Optional Text>
<Secondary Text>
.
サーバー:
// sends:
//
// 200 Data follows
// Hello world
// How are you?
// .
//
ASender.Reply.SetReply(200, 'Data follows');
ASender.Reply.Response.Add('Hello world');
ASender.Reply.Response.Add('How are you?');
クライアント:
TCPclient.SendCmd(theMessage, 200);
TCPclient.IOHandler.Capture(SomeTStringsObj);
+1と答え。レミー、このような詳細な解答をするためにtmeを取ってくれてありがとう。私はそれが他人を助けるために役立つことを願っています。 – Mawg