0
1

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 XE4 > udpサーバ > echo server

Last updated at Posted at 2015-05-08

受信したものをそのまま返信するエコーサーバー.

ポートは6000。
受信した文字列をそのまま返す。
SJISでやり取りする。

//---------------------------------------------------------------------------
void __fastcall TForm1::IdUDPServer1UDPRead(TIdUDPListenerThread *AThread, const TIdBytes AData,
          TIdSocketHandle *ABinding)
{
	String rcvdStr;
	Idglobal::_di_IIdTextEncoding encSJIS;

	encSJIS = IndyTextEncoding(932);

	int init_pos = 0;
	rcvdStr = encSJIS->GetString(AData, init_pos, AData.Length);

	Memo1->Lines->Add(L"rcvd:" + rcvdStr);

	String peerIP = ABinding->PeerIP;
	int peerPort = ABinding->PeerPort;

	IdUDPServer1->Send(peerIP, peerPort, rcvdStr, encSJIS);

}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
	IdUDPServer1->DefaultPort = 6000;
	IdUDPServer1->Active = true;
}
0
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?