C++Builder 多线程文件发送系统

这是一个使用C++Builder编写的多线程文件发送系统,通过TClientSocket和TServerSocket组件实现了文件的发送和接收。客户端选择文件后,将文件名发送到服务器,并分块传输文件内容。服务器端监听多个端口,接收文件并显示接收进度。代码中包含了文件选择、IP地址输入、端口通信、文件分块传输和多线程处理等关键功能。
摘要由CSDN通过智能技术生成

经常拜读各位大侠的文章,今天也自己发表一片.请大家批评指正.

文件发送端源代码

.h文件

#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ScktComp.hpp>
#include <Dialogs.hpp>
#include <Buttons.hpp>
#include <ComCtrls.hpp>
#include <Menus.hpp>
#include <ExtCtrls.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
        TOpenDialog *OpenDialog1;
        TSpeedButton *SpeedButton1;
        TComboBox *ComboBox1;
        TSpeedButton *SpeedButton2;
        TListView *ListView1;
        TLabel *Label1;
        TPopupMenu *PopupMenu1;
        TMenuItem *N1;
        TClientSocket *ClientSocket1;
        TSpeedButton *SpeedButton3;
        TPanel *Panel1;
        TStatusBar *StatusBar1;
       void __fastcall SpeedButton1Click(TObject *Sender);
       void __fastcall SpeedButton2Click(TObject *Sender);
       void __fastcall N1Click(TObject *Sender);
       void __fastcall ClientSocket1Read(TObject *Sender,
          TCustomWinSocket *Socket);
       void __fastcall SpeedButton3Click(TObject *Sender);
       void __fastcall ClientSocket1Error(TObject *Sender,
          TCustomWinSocket *Socket, TErrorEvent ErrorEvent,
          int &ErrorCode);
private: // User declarations
       void __fastcall DisplayHint(TObject *Sender);
public:  // User declarations
        int port;
        int FileCount;
        __fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif

#ifndef Unit2H
#define Unit2H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <ScktComp.hpp>
//---------------------------------------------------------------------------
class TSend : public TThread
{           
private:
        TClientSocket *p;
        AnsiString filename;
protected:
        void __fastcall Execute();
public:
       int index;
        __fastcall TSend(bool CreateSuspended,TClientSocket *p1,AnsiString file);
};
//---------------------------------------------------------------------------
#endif

.cpp文件

#include <vcl.h>
#pragma hdrstop
#include <vcl/dstring.h>
#include "Unit2.h"
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
AnsiString name;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
     Application->OnHint = DisplayHint;
     FileCount=0;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::SpeedButton1Click(TObject *Sender)
{
  if(OpenDialog1->Execute())
  name=OpenDialog1->FileName;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::SpeedButton2Click(TObject

评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值