LoginSignup
1

More than 5 years have passed since last update.

C++ Builder XE4, 10.2 Tokyo >TIdTCPClientを使った送信例

Last updated at Posted at 2017-02-13
動作環境
C++ Builder XE4
  Windows 7 Pro: 送信元
  Windows 10 Pro: 送信先

RAD Studio 10.2 Tokyo Update 2 (追記: 2017/12/28)

関連 http://qiita.com/7of9/items/afd179c6c27a349f4ec6

TClientSocketでのテキスト送信実装をTIdTCPClient使用に変更しようとしている。

上記リンクと同じような処理は
http://qiita.com/7of9/items/51bd31318c6e1332adbf
のコードを参考にして、以下のようにしてみた。

Unit1.cpp
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::debugB_tcpClick(TObject *Sender)
{
    char zbuf[20] = {0};

    IdTCPClient1->Host = "192.168.2.7";
    IdTCPClient1->Port = 2000;
    IdTCPClient1->Connect();

    for(int loop=0; loop < 3; loop++) {
        Application->ProcessMessages();
        Sleep(300);
    }

    strcpy(zbuf, "TEST");
    IdTCPClient1->IOHandler->WriteLn(zbuf);

    //
    Application->ProcessMessages();
    Sleep(300);

    // if (IdTCPClient1->IOHandler->CheckForDataOnSource(1000)) {
    //     受信処理
    // }

    IdTCPClient1->IOHandler->InputBuffer->Clear();

    IdTCPClient1->Disconnect();

}
//---------------------------------------------------------------------------

TClientSocket使用と同じように通信できた。

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
1