⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit1.cpp

📁 《Internet与TCP/IP程序设计之C++ Builder高手》配书盘光盘内容:书中的范例和运行范例所需的图像素材、网页素材等。
💻 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::Button1Click(TObject *Sender)
{
    ServerSocket->Active = true ;
    StatusBar1->SimpleText = "Listening ..." ;
    Button1->Enabled = false ;
    Button2->Enabled = true ;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button2Click(TObject *Sender)
{
    ServerSocket->Active = false ;
    StatusBar1->SimpleText = "Disconnected." ;
    Button1->Enabled = true ;
    Button2->Enabled = false ;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
    ServerSocket->Close() ;
    Close();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::txtSendKeyDown(TObject *Sender, WORD &Key,
      TShiftState Shift)
{
    if (Key == VK_RETURN)
    {
        ServerSocket->Socket->Connections[0]->SendText(txtSend->Text) ;
    }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ServerSocketAccept(TObject *Sender,
      TCustomWinSocket *Socket)
{
    StatusBar1->SimpleText = "Accept Connection from: " + Socket->RemoteAddress ;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ServerSocketClientConnect(TObject *Sender,
      TCustomWinSocket *Socket)
{
    StatusBar1->SimpleText = "Connected from: " + Socket->RemoteAddress ;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ServerSocketClientDisconnect(TObject *Sender,
      TCustomWinSocket *Socket)
{
    StatusBar1->SimpleText = "Disconnected from: " + Socket->RemoteAddress ;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ServerSocketClientError(TObject *Sender,
      TCustomWinSocket *Socket, TErrorEvent ErrorEvent, int &ErrorCode)
{
    StatusBar1->SimpleText = "Error from Client socket.";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ServerSocketClientRead(TObject *Sender,
      TCustomWinSocket *Socket)
{
    StatusBar1->SimpleText = "Message from: " + Socket->RemoteAddress;
    txtGet->Text = Socket->ReceiveText() ;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ServerSocketListen(TObject *Sender,
      TCustomWinSocket *Socket)
{
    StatusBar1->SimpleText = "Server Listen" ;
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

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