用indy的TIdTCPServer控件做服务器,怎样实现多线程.60CSDN
展开全部
下面是客户端上传文件的代码:
procedure TjhjlForm.uploadClick(Sender: TObject);
var
SendFileName,s:string;
SendFile: TFileStream;
today:string;
begin
if fjlb.Items.Count>2 then
begin
MessageDlg('最多只能上传三个附件',mtError,[mbOK],0);
exit;
end;
today:=AnsiReplaceText(datetimetostr(now()),':','');
today:=AnsiReplaceText(today,'-','');
today:=AnsiReplaceText(today,' ','');
upload.Enabled:=false;
open.Enabled:=false;
try
Tcpclient.Connect();
s:='upload...';
tcpclient.WriteLn(s);
SendFileName:=trim(filename.Text);
SendFile := TFileStream.Create(SendFileName, fmOpenRead);//创建一个TFileStream,打开我们要发送的文件
SendFileName:=today+ExtractFileName(SendFileName);
tcpclient.WriteLn(SendFileName);//把文件名发送给服务器
tcpclient.WriteLn(Mainform.yhm);//用户名
Tcpclient.WriteStream(SendFile);//使用流模式把文件发送
tcpclient.Disconnect;
SendFile.Free;
fjlb.Items.Add(SendFileName);
fjlb.ItemIndex:=0;
open.Enabled:=true;
del.Enabled:=true;
except
application.MessageBox('连接服务器失败!','提示',MB_OK);
end;
procedure TjhjlForm.uploadClick(Sender: TObject);
var
SendFileName,s:string;
SendFile: TFileStream;
today:string;
begin
if fjlb.Items.Count>2 then
begin
MessageDlg('最多只能上传三个附件',mtError,[mbOK],0);
exit;
end;
today:=AnsiReplaceText(datetimetostr(now()),':','');
today:=AnsiReplaceText(today,'-','');
today:=AnsiReplaceText(today,' ','');
upload.Enabled:=false;
open.Enabled:=false;
try
Tcpclient.Connect();
s:='upload...';
tcpclient.WriteLn(s);
SendFileName:=trim(filename.Text);
SendFile := TFileStream.Create(SendFileName, fmOpenRead);//创建一个TFileStream,打开我们要发送的文件
SendFileName:=today+ExtractFileName(SendFileName);
tcpclient.WriteLn(SendFileName);//把文件名发送给服务器
tcpclient.WriteLn(Mainform.yhm);//用户名
Tcpclient.WriteStream(SendFile);//使用流模式把文件发送
tcpclient.Disconnect;
SendFile.Free;
fjlb.Items.Add(SendFileName);
fjlb.ItemIndex:=0;
open.Enabled:=true;
del.Enabled:=true;
except
application.MessageBox('连接服务器失败!','提示',MB_OK);
end;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询