Ver Mensaje Individual
  #22  
Antiguo 27-05-2006
Status Quo Status Quo is offline
Miembro
 
Registrado: may 2006
Posts: 23
Reputación: 0
Status Quo Va por buen camino
Este es el código que recibe el fichero. Lo he puesto tal cual me dijo Seoane esque ya no me fío de lo que pongo yo...



Código Delphi [-]
 unit Unit1;
 
interface
 
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ScktComp, ComCtrls, idglobal, ExtCtrls, ShellAPI;
 
type
Paquete = record
Tipo: Integer;
Tamano: Integer;
TamaTotal:Integer;
NomFich:String;
Buffer: array[0..1024] of Byte;
end;
 
type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
Label1: TLabel;
GroupBox1: TGroupBox;
Edit1: TEdit;
Edit2: TEdit;
Label2: TLabel;
Label3: TLabel;
ProgressBar1: TProgressBar;
Timer1: TTimer;
StatusBar1: TStatusBar;
ClientSocket1: TClientSocket;
Edit3: TEdit;
procedure Button1Click(Sender: TObject);
procedure ServerSocket1Accept(Sender: TObject;
Socket: TCustomWinSocket);
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure ClientSocket1Read(Sender: TObject; Socket: TCustomWinSocket);
 
private
{ Private declarations }
IncommingStream: TFileStream;
TimeTaken: integer;
public
{ Public declarations }
end;
 
var
Form1: TForm1;
 
implementation
 
procedure TForm1.Button1Click(Sender: TObject);
begin
ClientSocket1.Address:=Edit3.Text;
ClientSocket1.Open;
 
end;
 
procedure TForm1.ServerSocket1Accept(Sender: TObject;
Socket: TCustomWinSocket);
begin
Memo1.Lines.Add('Client connected From '+Socket.RemoteHost)
 
end;
 
 
 
procedure TForm1.ClientSocket1Read(Sender: TObject;
Socket: TCustomWinSocket);
var
IncommingLen, RecievedLen: integer;
Filepath: string;
P: Paquete;
begin
 
Timer1.Enabled := True;
ClientSocket1.Socket.ReceiveBuf(P, Sizeof(P));
if p.Tipo=0 then
begin
freeAndNil(IncommingStream);
Edit1.Text:=p.NomFich;
IncommingStream := TFileStream.Create(Edit1.Text, fmCREATE or fmOPENWRITE and fmsharedenywrite);
end;
 
IncommingStream.WriteBuffer(p.Buffer,p.Tamano);
 
if p.Tamano< Sizeof(p.Buffer) then
begin
freeAndNil(IncommingStream);
memo1.Lines.Add('File '+Edit1.Text +' Recieved Successfuly');
memo1.Lines.Add('Time Taken to Recieve File ' +IntToStr(TimeTaken)+' seconds');
ClientSocket1.Socket.SendText('DONE!');
Edit1.Text := '';
Edit2.Text := '';
ProgressBar1.Position := 0;
Timer1.Enabled := False;
TimeTaken := 0;
 
if Messagedlg('Would you Like to open the recieved file?', mtConfirmation, [MbYes,MbNo],0) = MrYes then
begin
ShellExecute(Form1.Handle, 'open', pchar(Filepath),nil, nil, SW_NORMAL);
end;
 
end;
end;
 
 
procedure TForm1.FormCreate(Sender: TObject);
begin
Memo1.Text := '';
end;
 
procedure TForm1.Timer1Timer(Sender: TObject);
begin
inc(TimeTaken,1);
 
end;
 
end.





Creo que ya me va quedando poco para conseguirlo...pero aún necesito un poco más de ayudita...
Responder Con Cita