Club Delphi  
    Paypal   FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Varios
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Coloboración Paypal con ClubDelphi

 
 
Herramientas Buscar en Tema Desplegado
  #21  
Antiguo 27-05-2006
Status Quo Status Quo is offline
Miembro
 
Registrado: may 2006
Posts: 23
Poder: 0
Status Quo Va por buen camino
Red face no puedo extraer el nombre del fichero

He puesto un solo socket para envíar los paquetes y he puesto el record así:


type
Paquete = record
Tipo: Integer;
Tamano: Integer;
TamaTotal:Integer;
NomFich:String;
Buffer: array[0..1024] of Byte;
end;


No se si habrá algún problema con los strings pero el caso esque no me llega el nombre en el código de recepción...

Pongo todo el código con el que estoy trabajando para hacer las pruebas(luego lo pasaré al que estoy haciendo yo...)

No se lo que son los tipos NonBlocking yo utilizo de la paleta de componentes--> internet el componente clientsockect y serversocket...

Seoane, te pongo el código este de pruebas...Cuando lo terminte(por favor que sea pronto) te paso el programa total...(como tu me digas que te viene mejor...)


Este es el código que envía el fichero:


Código Delphi [-]
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ScktComp, StdCtrls;
type
Paquete = record
Tipo: Integer;
Tamano: Integer;
TamaTotal:Integer;
NomFich:String;
Buffer: array[0..1024] of Byte;
end;

type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Memo1: TMemo;
Edit1: TEdit;
Edit2: TEdit;
GroupBox1: TGroupBox;
Label1: TLabel;
Label2: TLabel;
Edit3: TEdit;
Label3: TLabel;
OpenDialog1: TOpenDialog;
ServerSocket1: TServerSocket;
procedure Button1Click(Sender: TObject);
procedure ClientSocket1Connect(Sender: TObject;
Socket: TCustomWinSocket);
procedure ClientSocket2Connect(Sender: TObject;
Socket: TCustomWinSocket);
procedure Button2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
private
{ Private declarations }
Streamsize: TFileStream;
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation


procedure TForm1.Button1Click(Sender: TObject);
begin
ServerSocket1.Open;

end;

procedure TForm1.ClientSocket1Connect(Sender: TObject;
Socket: TCustomWinSocket);
begin
Memo1.Lines.Add('Connected to ' +Socket.RemoteHost); // Shows the address of the server you connect to
end;

procedure TForm1.ClientSocket2Connect(Sender: TObject;
Socket: TCustomWinSocket);
begin
Memo1.Lines.Add('Sending File ' +Edit1.Text +' .........')
end;

procedure TForm1.Button2Click(Sender: TObject);
var
stream:TStream;


P: Paquete;

begin
if ServerSocket1.Active = True then

begin
OpenDialog1.Filter := 'All Files (*.*)'; // you can add more choices by adding | and followed by description and (*.extension)
OpenDialog1.FilterIndex := 1; // Here you follow which index number from above you want
if OpenDialog1.Execute then
begin
Edit1.Text := ExtractFileName(OpenDialog1.FileName); // To send as filename after

Streamsize := TFileStream.Create(OpenDialog1.FileName, fmopenread); // Stream created just to Calculate size
Edit2.Text := inttostr(Streamsize.Size);

Streamsize.Position := 0;
Streamsize.Free;
sleep(2000);


stream:=TFileStream.Create(OpenDialog1.FileName, fmopenRead);

P.Tipo:= 0;
repeat
Application.ProcessMessages;
P.Tamano:= stream.Read(P.Buffer,SizeOf(P.Buffer));
P.NomFich:=Edit1.Text;
P.TamaTotal:=Streamsize.Size;
ServerSocket1.Socket.Connections[0].SendBuf(P,sizeof(P));  //he quitado el -1
//leidos:=stream.Read(P.Buffer,SizeOf(P.Buffer));
P.Tipo:= 1;
until(P.Tamano=0);
stream.Free;

end;
end
else
MessageDlg('Error: You are not connected', mtError, [MbOK],0); // Error Check above code won't work until the socket is connected
end;


procedure TForm1.FormCreate(Sender: TObject);
begin
Memo1.Text := '';
end;


procedure TForm1.ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
var IncommingText, StrippedData, CommandName: string;
begin
IncommingText := socket.ReceiveText; // Put all incoming data into this string
StrippedData := copy(IncommingText,6,length(IncommingText) ); // letters 6 to end is the actual data being sent
CommandName := copy(IncommingText,0,5); // letters 0 to 5 is the fixed letter space for the command name
if CommandName = 'DONE!' then // Expected command Done! note : This is case sensitive so match has to be the same case
begin
Memo1.Lines.Add('File ' +Edit1.Text +' ' +Edit2.Text +' was Recieved Successfully');

Edit1.Text := '';
Edit2.Text :='';
end;
end;

end.

Perdonar, no se porqué se me ha ido toda la indentación...

Última edición por Status Quo fecha: 28-05-2006 a las 16:49:16.
Responder Con Cita
 



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Recorrer arreglo Perrero80 Varios 3 18-05-2006 22:52:27
Compatibilidad entre PChar y String vick Conexión con bases de datos 5 24-10-2005 21:50:35
¿como pasar de String dentro de un PChar? Moises22 Varios 6 27-09-2005 15:43:47
Pchar y String superhopi Varios 8 19-08-2004 09:54:06
problemas de compatibilidad de tipos pchar y string VRO Varios 2 13-05-2004 10:29:34


La franja horaria es GMT +2. Ahora son las 23:24:10.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi