Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

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

Grupo de Teaming del ClubDelphi

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 06-07-2011
maxinitto maxinitto is offline
Miembro
 
Registrado: may 2010
Posts: 45
Poder: 0
maxinitto Va por buen camino
pero si asi es como lo hago yo jejejejejejej mira aqui te pongo otra captura en otro servidor

Responder Con Cita
  #2  
Antiguo 06-07-2011
beginner01 beginner01 is offline
Miembro
NULL
 
Registrado: mar 2011
Ubicación: República Dominicana
Posts: 181
Poder: 14
beginner01 Va por buen camino
así es difícil saber porque te da el error solo se me ocurre que son problemas con los puertos. prueba cambiando los puertos de
serversocket2 y clientsocket2
Responder Con Cita
  #3  
Antiguo 06-07-2011
maxinitto maxinitto is offline
Miembro
 
Registrado: may 2010
Posts: 45
Poder: 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
  #4  
Antiguo 07-07-2011
maxinitto maxinitto is offline
Miembro
 
Registrado: may 2010
Posts: 45
Poder: 0
maxinitto Va por buen camino
Ala ya lo solucione el problema estaba en la desordenada ejecucion del codigo aqui adjunto el .zip con el proyecto por que seguro que a alguien le sera de utilidad y nada tema cerrado gracias por toda la ayuda.
Archivos Adjuntos
Tipo de Archivo: zip Socket.zip (13,3 KB, 106 visitas)
Responder Con Cita
Respuesta



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
Enviar y recibir archivos con TCPCliente y TCPServer victork_py Internet 4 16-07-2015 01:42:01
archivos binarios kazcote Varios 5 05-12-2005 04:02:35
Enviar y Recibir Archivos (Codigo para hacerlo) juliopag1 Internet 0 17-05-2005 21:22:44
¿Cómo puedo enviar y recibir archivos vía IRC con el componente TIdIRC? DarkByte Internet 4 26-06-2004 17:54:05
archivos exe y/o binarios fcran Varios 2 26-06-2003 14:34:21


La franja horaria es GMT +2. Ahora son las 11:23:12.


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