Ver Mensaje Individual
  #19  
Antiguo 06-07-2011
maxinitto maxinitto is offline
Miembro
 
Registrado: may 2010
Posts: 45
Reputación: 0
maxinitto Va por buen camino
mira te explico, cogi el codigo ese y lo adapte a mi programa ya que mis socket si funcionan....

desde el cliente envio un mensaje al recibir el servidor dicho mensaje ejecuta esto

Código Delphi [-]
EnviarArchivo('ImageList.dat');

procedure EnviarArchivo(nombre : string);
var
 FileSize : String;
begin

 Form1.s.Socket.SendText('FILE!'+nombre);
 sleep(2000); // Need to sleep so the other end has time to process the commands
 Form1.FStream := TFileStream.Create(nombre, fmopenread); // Stream created just to Calculate size
 FileSize := inttostr(Form1.FStream.Size);
 Sleep(2000);
 Form1.s.Socket.SendText('SIZE!' + FileSize); // Sends filesize through primary socket
 Form1.FStream.Position := 0;
 Form1.FStream.Free;
 sleep(2000);
 Form1.s2.Socket.SendStream(TFileStream.Create(nombre, fmopenRead));

end;

que si te fijas es el codigo del boton del cliente del codigo que me pasastes ese, el de enviar arhivo.

aki el onread del socket1 y el del socket 2

Código Delphi [-]
procedure TForm2.cClientRead(Sender: TObject; Socket: TCustomWinSocket);
var
 IncommingText, StrippedData, CommandName: string;
begin

     IncommingText := PansiChar(socket.ReceiveText);
     StrippedData := copy(IncommingText,6,length(IncommingText) );
     CommandName := copy(IncommingText,0,5);
     FileSizes := StrippedData;
     if CommandName = 'FILE!' then
        FStream := TFileStream.Create('ImageList.dat', fmCREATE or fmOPENWRITE and fmsharedenywrite);

end;

procedure TForm4.c2ClientRead(Sender: TObject; Socket: TCustomWinSocket);
var
  textorecibido : String;
  res , res2: TStringDynArray;
  lvitem : TListItem;
  i , j : integer;
  Buffer: array [0..9999] of Char;
  IncommingLen, RecievedLen: integer;
  Filepath: string;
begin

if TV_Opciones.Selected.Text = 'Archivos' then
begin

  if Pos('CojoUnidades', textorecibido) = 1 then
  begin
    res := Explode('|', textorecibido);
    for i := 1 to high(res) do
      CB_Unidades.Items.Add(res[i]);
  end;

if Pos('Directorios', textorecibido) = 1 then
begin
    res := Explode('---', textorecibido);

    for i := 1 to high(res)-1 do
    begin
      res2 := Explode('|', res[i]);
      lvitem := LV_ArchivosRecibidos.Items.Add;
      lvitem.Caption := res2[0];
      lvitem.SubItems.add(res2[1]);
      if res2[1] = 'Carpeta' then
        lvitem.ImageIndex := 0
      else
        lvitem.ImageIndex := StrToInt(res2[2]);
    end;

  end;
  exit;

end;



   Timer1.Enabled := True;
   IncommingLen := socket.ReceiveLength;

    // Sets a String Filepath for the actual directory with the filename so that the shellexecute can run this after
    while IncommingLen > 0 do
    begin
       RecievedLen := socket.ReceiveBuf(Buffer, Sizeof(Buffer));
       // Changes the size of RecievedLen by the amount of incoming data recieved
    if RecievedLen <= 0 then
    // Small part of the code where once the buffer reaches 0 the code will exit
       Break
    else
    FStream.Write(Buffer, RecievedLen);

    // through the primary socket Also this line increases the progess indicator bar
    if FStream.Size >= StrToInt(FileSizes) then
    // Onces the stream size begins to reach the size which was sent before sending the file then this
    begin
     // procedure will start
       FStream.Free;
       Timer1.Enabled := False;
       TimeTaken := 0;
       Break;                                                                         // This line basically executes any file using the extension from the windows ini files.
    end;
    end;

end;

bueno pues no se que hago mal xk me llega el archivo vacio con 0 kb , pero ahora el error de antes no lo da, ese error se debia a que los sockets no estaban conectados, bueno aver si me pueden echar un cable por que por lo visto hay mas de uno que le cuesta y esto que digo de que le cuesta sabe para quien va jejeje saludos
Responder Con Cita