H
hzm7512
Unregistered / Unconfirmed
GUEST, unregistred user!
//服务器端函数,负责发送接受文件的
procedure TGetFileServerThread.ClientExecute;
var
Retxt : string;
n : integer;
Data : array[0..4095] of char;
SocketStream : TWinSocketStream;
begin
while not Terminated and ClientSocket.Connected do try
SocketStream := TWinSocketStream.Create(ClientSocket, 60000
try
FillChar(Data, SizeOf(Data), 0);
if SocketStream.Read(Data, SizeOf(Data)) = 0 then begin
//如果1分钟之内没有数据关闭socket
ClientSocket.Close;
Terminate;
end;
Retxt := Trim(Data);
if length(Retxt) > 0 then begin
if Pos('<Send>', Retxt) > 0 then
SendFile(Retxt)
else
Getfile(Retxt);
end;
finally
SocketStream.Free;
end;
except
HandleException;
end;
end;
//客户端函数,当有文件信息时调用此函数
//socket类型:ctNonBlocking
procedure TReceiveFileThread.GetFileinfo(Fileinfo: string);
var
i : integer;
FileTypestr : string;
begin
try
if not ClientForm.ClientSocketFile.Active then
ClientForm.ClientSocketFile.Open;
if ClientForm.ClientSocketFile.Active then begin
Split(Fileinfo, '*', Fileinfolist);
i := Pos('/', Fileinfolist[0]);
Filenamestr := Copy(Fileinfolist[0], i + 1, length(Fileinfolist[0]) - i);
FileSourcestr := Fileinfolist[2];
Filestream := TFileStream.Create(CurrentApp_Dirstr + '/' + Fileinfolist[0],
fmCreate
or fmOpenWrite);
filesize_int := strtoint(Fileinfolist[1]);
ClientForm.ClientSocketFile.Socket.SendText('<Send>' + Fileinfolist[0]);
end
except
end;
end;
procedure TGetFileServerThread.ClientExecute;
var
Retxt : string;
n : integer;
Data : array[0..4095] of char;
SocketStream : TWinSocketStream;
begin
while not Terminated and ClientSocket.Connected do try
SocketStream := TWinSocketStream.Create(ClientSocket, 60000
try
FillChar(Data, SizeOf(Data), 0);
if SocketStream.Read(Data, SizeOf(Data)) = 0 then begin
//如果1分钟之内没有数据关闭socket
ClientSocket.Close;
Terminate;
end;
Retxt := Trim(Data);
if length(Retxt) > 0 then begin
if Pos('<Send>', Retxt) > 0 then
SendFile(Retxt)
else
Getfile(Retxt);
end;
finally
SocketStream.Free;
end;
except
HandleException;
end;
end;
//客户端函数,当有文件信息时调用此函数
//socket类型:ctNonBlocking
procedure TReceiveFileThread.GetFileinfo(Fileinfo: string);
var
i : integer;
FileTypestr : string;
begin
try
if not ClientForm.ClientSocketFile.Active then
ClientForm.ClientSocketFile.Open;
if ClientForm.ClientSocketFile.Active then begin
Split(Fileinfo, '*', Fileinfolist);
i := Pos('/', Fileinfolist[0]);
Filenamestr := Copy(Fileinfolist[0], i + 1, length(Fileinfolist[0]) - i);
FileSourcestr := Fileinfolist[2];
Filestream := TFileStream.Create(CurrentApp_Dirstr + '/' + Fileinfolist[0],
fmCreate
or fmOpenWrite);
filesize_int := strtoint(Fileinfolist[1]);
ClientForm.ClientSocketFile.Socket.SendText('<Send>' + Fileinfolist[0]);
end
except
end;
end;