📄 unit2.pas
字号:
socket.Close;
RecNo:=1;
exit;
end;
end else
begin
Image1.Picture.Bitmap:=XORbmp;
FirstFrame:=False;
end;
except
Socket.Close;
exit;
end;
Label8.Caption:='显示完毕,等待...';
Gauge4.Progress:=0;
end;
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
{$R+}
end;
procedure TForm2.FormDestroy(Sender: TObject);
begin
MonitorCSocket1.Close;
XoRBmp.Free;
XoRJPG.Free;
GFileDirStream.Free;
end;
procedure TForm2.NMUDP2DataReceived(Sender: TComponent;
NumberBytes: Integer; FromIP: String; Port: Integer);
Var
AStream:TStringStream;
begin
AStream:=TStringStream.Create('');
NMUDP2.ReadStream(AStream);
OutLine2.Lines.LoadFromStream(AStream);
Label28.Caption:='共:'+IntToStr(OutLine2.Lines.Count)+'个'
+IntToStr(AStream.Size)+'字节';
end;
procedure TForm2.LinkUDPDataReceived(Sender: TComponent;
NumberBytes: Integer; FromIP: String; Port: Integer);
Var
AStream:TStringStream;
begin
AStream:=TStringStream.Create('');
LinkUDP.ReadStream(AStream);
end;
procedure TForm2.SSocket1ClientConnect(Sender: TObject;
Socket: TCustomWinSocket);
begin
//StatusBar3.Panels[1].Text:=Socket.RemoteAddress+'->正进入连接...!';
GSaveStream.Clear;
Gauge1.Progress:=0;
end;
procedure TForm2.CheckListBox4DblClick(Sender: TObject);
Var
LinkFlagStream:TStringStream;
begin
LinkFlagStream:=TStringStream.Create('File transfer begin');
LinkUDP.RemoteHost:=MaskEdit2.Text;
LinkUDP.SendStream(LinkFlagStream);
end;
procedure TForm2.MaskEdit2DblClick(Sender: TObject);
Var
FileFilt:TStringStream;
begin
NMUDP1.RemoteHost:=MaskEdit2.Text;
NMUDP1.remotePort:=92;
FileFilt:=TStringStream.Create('$');
SendFileExUDP.RemoteHost:=MaskEdit2.Text;
SendFileExUDP.RemotePort:=55555;
try
SendFileExUDP.SendStream(FileFilt);
OutLine1.Enabled:=False;
except
FileFilt.Free;
end;
FileFilt.Free;
end;
procedure TForm2.BitBtn3Click(Sender: TObject);
Var
DataStream:TStringStream;
iLStat:integer;
begin
BitBtn3.Enabled:=False;
SSocket1.Open;
// TCP<->TCP 可靠连接传输方式
if (SpeedButton81.Down and SpeedButton84.Down) then
Begin
try
if CFileSocket.Active=TRUE then
Begin
Label18.Caption:='正请求下载...';
Repeat
iLStat:=CFileSocket.Socket.SendText('DLD'+ComboBox1.Text);
if iLStat=0 then Application.ProcessMessages;
until iLStat<>0;
end else Label18.Caption:='目标主机已断开!';
except
exit;
end;
exit;
end;
// UDP<->UDP 快速连接传输方式
Try
DataStream:=TStringStream.Create(ComboBox1.Text);
NMUDP2.SendStream(DataStream);
except
DataStream.Free;
end;
DataStream.Free;
end;
procedure TForm2.SpeedButton6Click(Sender: TObject);
Var
LinkFlagStream:TStringStream;
iLStat:integer;
begin
NMUDP1.RemoteHost:=MaskEdit2.Text;
NMUDP2.RemoteHost:=MaskEdit2.Text;
UDPReceiveFileStream.Clear;
if SpeedButton81.Down=false then
//UDP<->UDP 快速简易连接
begin
if ComboBox1.Text='' then
ComboBox1.Text:='C:\';
SelectDir:=ComboBox1.Text;
LinkFlagStream:=TStringStream.Create(ComboBox1.text);
LinkUDP.RemoteHost:=MaskEdit2.Text;
LinkUDP.SendStream(LinkFlagStream);
FileExPanel.Visible:=False;
exit;
end else
//UDP--->TCP<--->TCP 反向连接
if SpeedButton83.Down=True then
Begin
if ComboBox1.Text='' then ComboBox1.Text:='C:\';
SelectDir:=ComboBox1.Text;
LinkFlagStream:=TStringStream.Create('*'+ComboBox1.text);
LinkUDP.RemoteHost:=MaskEdit2.Text;
LinkUDP.SendStream(LinkFlagStream);
GFileDirStream.Clear;
SFileSocket.Open;
exit;
end else
if SpeedButton84.Down= True then
//TCP<--->TCP 安全连接
Begin
if ComboBox1.Text='' then ComboBox1.Text:='C:\';
SelectDir:=ComboBox1.Text;
if CFileSocket.Active=TRUE then
Begin
Repeat
iLStat:=CFileSocket.Socket.SendText(SelectDir);
if iLStat=0 then Application.ProcessMessages;
until iLStat<>0;
end;
end else
if SpeedButton82.Down= True then
//UDP<->UDP<-->TCP<--->TCP<--->TCP 代理连接
begin
end;
end;
procedure TForm2.SpeedButton7Click(Sender: TObject);
var
i,iLStat:Integer;
MidStr,UseStr:String;
LinkFlagStream:TStringStream;
begin
OutLine1.Enabled:=True;
NMUDP1.RemoteHost:=MaskEdit2.Text;
NMUDP2.RemoteHost:=MaskEdit2.Text;
UDPReceiveFileStream.Clear;
MidStr:=ComboBox1.Text;
UseStr:='';
repeat
i:=pos('\',MidStr);
UseStr:=UseStr+copy(MidStr,1,i);
MidStr:=Copy(MidStr,i+1,Length(MidStr)-i);
Until i=0;
if copy(UseStr,Length(UseStr),1)='\' then
UseStr:=Copy(UseStr,1,Length(UseStr)-1);
ComboBox1.Text:=UseStr;
UDPReceiveFileStream.Clear;
if ComboBox1.Text='' then
begin
DriveID:=1;
ComboBox1.Text:='C:\';
end;
SelectDir:=ComboBox1.Text;
//UDP<----->UDP 快速连接
if SpeedButton81.Down=false then
begin
LinkFlagStream:=TStringStream.Create(ComboBox1.text);
LinkUDP.RemoteHost:=MaskEdit2.Text;
LinkUDP.SendStream(LinkFlagStream);
FileExPanel.Visible:=False;
end else
//UDP--->TCP<--->TCP 反向连接
if SpeedButton83.Down=True then
Begin
if ComboBox1.Text='' then ComboBox1.Text:='C:\';
SelectDir:=ComboBox1.Text;
LinkFlagStream:=TStringStream.Create('*'+ComboBox1.text);
LinkUDP.RemoteHost:=MaskEdit2.Text;
LinkUDP.SendStream(LinkFlagStream);
GFileDirStream.Clear;
SFileSocket.Open;
exit;
end else
if SpeedButton84.Down= True then
//TCP<--->TCP 安全连接
Begin
if ComboBox1.Text='' then ComboBox1.Text:='C:\';
SelectDir:=ComboBox1.Text;
if CFileSocket.Active=TRUE then
Begin
Repeat
iLStat:=CFileSocket.Socket.SendText(SelectDir);
if iLStat=0 then Application.ProcessMessages;
until iLStat<>0;
end;
end else
//UDP<->UDP<-->TCP<--->TCP<--->TCP 代理连接
if SpeedButton82.Down= True then
begin
end;
end;
procedure TForm2.SpeedButton8Click(Sender: TObject);
begin
SavePictureDialog1.DefaultExt:='*.jpg';
if SavePictureDialog1.Execute then
Image1.Picture.SaveToFile(SavePictureDialog1.FileName);
end;
procedure TForm2.MaskEdit1Change(Sender: TObject);
begin
MonitorCSocket1.Close;
end;
procedure TForm2.SpeedButton9Click(Sender: TObject);
Var
ReplaceFNStream:TStringStream;
iLStat:integer;
begin
ReplaceSocket.Open;
RemoteSaveID:=8;
// TCP<->TCP 可靠连接传输方式
if (SpeedButton81.Down and SpeedButton84.Down) then
Begin
try
if CFileSocket.Active=TRUE then
Begin
Repeat
iLStat:=CFileSocket.Socket.SendText('SAS'+ComboBox1.Text);
if iLStat=0 then Application.ProcessMessages;
until iLStat<>0;
end;
except
exit;
end;
exit;
end;
// UDP<--->UDP 快速连接传输方式
Try
ReplaceUDP.RemoteHost:=MaskEdit2.Text;
ReplaceFNStream:=TStringStream.Create(ComboBox1.Text);
ReplaceUDP.SendStream(ReplaceFNStream);
except
ReplaceFNStream.Free;
exit;
end;
ReplaceFNStream.Free;
end;
procedure TForm2.ReplaceSocketClientConnect(Sender: TObject;
Socket: TCustomWinSocket);
{R-}
var
FileMStream :TMemoryStream;
SendBuffer :Array[1..4096] of Char;
ReadSize,Sendstatus :integer;
SendSizeAll :longint;
begin
//*******替换*************************************************
if RemoteSaveID=8 then
begin
OpenDialog1.Filter:='*'+ExtractFileExt(ComboBox1.Text);
OpenDialog1.FileName:='*'+ExtractFileExt(ComboBox1.Text);
OpenDialog1.Title:='将远端文件内容'+ComboBox1.Text+'替换由:';
if OpenDialog1.Execute then
Begin
FileMStream:=TMemoryStream.Create;
FileMStream.LoadFromFile(OpenDialog1.FileName);
FileMStream.Position:=0;
Gauge2.MaxValue:=100;
Gauge2.MinValue:=0;
Gauge2.Progress:=0;
readSize :=0;
SendSizeAll:=0;
Repeat
readSize:=FileMStream.Read(SendBuffer,4096);
try
Repeat
SendStatus:=Socket.SendBuf(SendBuffer,readSize);
if SendStatus=-1 then Application.ProcessMessages;
until SendStatus<>-1;
except
Label13.Caption:='(替换)文件传输失败!';
FileMStream.Free;
exit;
end;
SendSizeAll:=SendSizeAll+readSize;
try
Gauge2.Progress:=(SendSizeAll*100) div FileMStream.Size;
except
Label13.Caption:='(替换)文件传输显示异常!';
end;
readSize :=0;
until SendSizeAll>=FileMStream.Size;
repeat
SendStatus:=Socket.SendText('$$$$$$$$');
until SendStatus<>0;
Label13.Caption:='(替换)文件传输成功!';
FileMStream.Free;
end;
OpenDialog1.Filter:='';
end;
//*****远程存储*****************************************************************
if RemoteSaveID=18 then
begin
FileMStream:=TMemoryStream.Create;
FileMStream.LoadFromFile(OpenDialog2.FileName);
FileMStream.Position:=0;
Gauge3.MaxValue:=100;
Gauge3.MinValue:=0;
Gauge3.Progress:=0;
readSize :=0;
SendSizeAll:=0;
Repeat
readSize:=FileMStream.Read(SendBuffer,4096);
try
Repeat
SendStatus:=Socket.SendBuf(SendBuffer,readSize);
if SendStatus=-1 then Application.ProcessMessages;
until SendStatus<>-1;
except
Label28.Caption:='对不起:文件传输失败!';
FileMStream.Free;
Exit;
end;
SendSizeAll:=SendSizeAll+readSize;
try
Gauge3.Progress:=(SendSizeAll*100) div FileMStream.Size;
except
Label28.Caption:='数据显示进程异常!';
end;
readSize :=0;
until SendSizeAll=FileMStream.Size;
repeat
SendStatus:=Socket.SendText('$$$$$$$$');
until SendStatus<>0;
Label28.Caption:='(存储)文件传输成功!';
FileMStream.Free;
end;
{R+}
end;
procedure TForm2.ComboBox1DblClick(Sender: TObject);
begin
DriveID:=DriveID+1;
if DriveID=5 then DriveID:=1;
if DriveID=1 then ComboBox1.Text:='C:\';
if DriveID=2 then ComboBox1.Text:='D:\';
if DriveID=3 then ComboBox1.Text:='E:\';
if DriveID=4 then ComboBox1.Text:='F:\';
SpeedButton7Click(self);
end;
procedure TForm2.SpeedButton10Click(Sender: TObject);
Var
ReplaceFNStream:TStringStream;
TheSaveDir,TheFileName:String;
iLStat:integer;
begin
TheSaveDir:=ExtractFileDir(ComboBox1.Text);
if TheSaveDir<>'' then
begin
if OpenDialog2.Execute then
begin
ReplaceSocket.Open;
RemoteSaveID:=18;
TheFileName:=ExtractFileName(OpenDialog2.FileName);
// TCP<->TCP 可靠连接传输方式
if (SpeedButton81.Down and SpeedButton84.Down) then
Begin
try
if CFileSocket.Active=TRUE then
Begin
Repeat
iLStat:=CFileSocket.Socket.SendText('SAV'+TheSaveDir+'\'+TheFileName);
if iLStat=0 then Application.ProcessMessages;
until iLStat<>0;
end;
except
exit;
end;
exit;
end;
// UDP<--->UDP 快速连接传输方式
ReplaceUDP.RemoteHost:=MaskEdit2.Text;
ReplaceFNStream:=TStringStream.Create(TheSaveDir+'\'+TheFileName);
ReplaceUDP.SendStream(ReplaceFNStream);
ReplaceFNStream.Free;
end;
end else label28.Caption:='错误目录选择!';
end;
procedure TForm2.SpeedButton5Click(Sender: TObject);
begin
sendstate:=0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -