mainform.cpp

来自「C++ BUILDER精彩编程实例集锦(源码) 第一部分 界面设计 第二部分」· C++ 代码 · 共 57 行

CPP
57
字号
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Mainform.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
   this->Memo1->Text="";
   this->RichEdit1->Text="";
}
//---------------------------------------------------------------------------


void __fastcall TForm1::BitBtn1Click(TObject *Sender)
{//监听
   this->ServerSocket->Port=StrToInt(this->Edit1->Text);
   this->ServerSocket->Active=true;
   this->StatusBar1->SimpleText="正在监听客户端连接状态......";
}
//---------------------------------------------------------------------------

void __fastcall TForm1::BitBtn3Click(TObject *Sender)
{//断开
   this->ServerSocket->Close();
   this->StatusBar1->SimpleText="已经断开与客户端的连接";
}
//---------------------------------------------------------------------------

void __fastcall TForm1::BitBtn4Click(TObject *Sender)
{//发送
   this->ServerSocket->Socket->Connections[0]->SendText(this->RichEdit1->Text);
}
//---------------------------------------------------------------------------

void __fastcall TForm1::ServerOnAccept(TObject *Sender,
      TCustomWinSocket *Socket)
{
  this->RichEdit1->Clear();
  this->StatusBar1->SimpleText="连接到:"+this->ServerSocket->Socket->RemoteAddress;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::ServerOnClientRead(TObject *Sender,
      TCustomWinSocket *Socket)
{
  this->Memo1->Lines->Add(Socket->ReceiveText());
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?