0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

C++ Builder / Indy > TStreamの送信 > WriteStream()でなくWrite()のようだ

Last updated at Posted at 2017-02-14
動作環境
C++ Builder XE4

関連 http://qiita.com/7of9/items/9fa80d146d3fab63a71b

TClientSocketの通信切断の症状の対処としてIndyのTCP/IP通信に実装を変更している。
読込みの方は動き出した。

書込み処理が失敗しているようだ。

失敗例

Unit1.cpp
    char zbuf[50] = // 何かのバイナリデータ
    for(int idx=0; idx < len; idx++) {
	IdTCPClient1->IOHandler->Write(&zbuf[idx]);
    }

上記の送信方法では失敗していた。
理由としてはASCIIで扱えない>=128の値が入った時の処理に関連すると思われる。

成功例

以下で送信できたようだ。

読込みはReadStream()というAPIがある一方、書込みはWrite()のようだ。

Unit1.cpp
# include <memory> // for unique_ptr

...
	std::unique_ptr<TMemoryStream> strm(new TMemoryStream());
	strm->Write(pkt, len);
	strm->Seek(0, 0); // 先頭に戻る
	IdTCPClient1->IOHandler->Write(strm.get(), len);
...

TClientSocketでの動作と同じ通信結果が得られるようになった。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?