hello guys, I need to understand how to send files with my class. It works well for sending strings. But I must also send and receive files. Who tells me how to do?
thanks
unit Unit_Client_TCP;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, blcksock;
type
{ TTCPClient }
TTCPClient=class
private
sock: TTCPBlockSocket;
buffer: String;
ErrorStr: string;
public
constructor Create(Host: string; Port: string);
function GetErrorStr(): string;
function SendString(str: string): boolean;
function GetString(): string;
destructor Free();
end;
implementation
{ TTCPClient }
constructor TTCPClient.Create(Host: string; Port: string);
begin
Self.Buffer:='';
sock := TTCPBlockSocket.Create;
sock.Connect(Host, Port);
// Was there an error?
if sock.LastError <> 0 then
begin
Self.ErrorStr:=sock.LastErrorDesc;
end;
end;
function TTCPClient.GetErrorStr: string;
begin
result:=Self.ErrorStr;
end;
function TTCPClient.SendString(str: string): boolean;
begin
sock.SendString(str + #13#10);
end;
function TTCPClient.GetString: string;
begin
buffer := sock.RecvPacket(2000);
result:=buffer;
end;
destructor TTCPClient.Free;
begin
Self.sock.CloseSocket;
Self.sock.Free;
end;
end.