📄 mainform.cpp
字号:
//---------------------------------------------------------------------------
#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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -