C++Builder相談室 Part21 (327レス)
前次1-
抽出解除 必死チェッカー(本家) (べ) 自ID レス栞 あぼーん

127: 2019/11/19(火)21:31 ID:oTHzii8i(1/2)調 AAS
TIdTCPServer + TIdTCPClientで数MBの長大な文字列を送受信する場合はどうしたらいいのでしょうか?

Client(送信)側:
  TIdBytes buf;

  buf = TEncoding::UTF8->GetBytes(SendStr);
 IdClient->IOHandler->Write(buf, buf.Length);

Server(受信)側:
void __fastcall TForm1::IdTCPServerExecute(TIdContext *AContext)
{
  TIdBytes buf;

  AContext->Connection->IOHandler->ReadBytes(buf, -1);
  RecvStr = TEncoding::UTF8->GetString(buf);
}

これだと最初の32768バイトだけ受信されている状態でした。
129: 2019/11/19(火)23:22 ID:oTHzii8i(2/2)調 AAS
>>128
ありがとうございます。
とりあえずこんな感じにしたらできました。

void __fastcall TForm1::IdTCPServerExecute(TIdContext *AContext)
{
 TIdBytes buf;

 if (!AContext->IOHandler->InputBufferIsEmpty()) {
  buf.Length = 0;
  while(1) {
   AContext->Connection->IOHandler->CheckForDataOnSource(100);
   if (!AContext->IOHandler->InputBufferIsEmpty()) {
    break;
   }
   AContext->Connection->IOHandler->ReadBytes(buf, -1, true);
  }
  RecvStr = TEncoding::UTF8->GetString(buf);
 }
}
前次1-
スレ情報 赤レス抽出 画像レス抽出 歴の未読スレ AAサムネイル

ぬこの手 ぬこTOP 0.025s