Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

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

Grupo de Teaming del ClubDelphi

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 18-03-2011
kdemia kdemia is offline
Miembro
 
Registrado: may 2010
Posts: 109
Poder: 14
kdemia Va por buen camino
Unhappy Enviar Imagen (TClientSocket/TServerSocket)

que tal gente, bueno acudo nuevamente a ustedes para que me ayuden en mi problema:
necesito mandar una imagen.. bien?, bueno a la imagen la transformo en un stream y la mando algo asi
Código Delphi [-]
ClientSocket.Socket.SendStream(ImgStream)
el tema es que no tengo una manera, o por lo menos la desconosco, de leer el stream, es decir recivirlo algo asi:
Código Delphi [-]
Imagen.Picture.Bitmap.Assign(ServerSocket.Socket.ReceiveStream)
pasa que la supuesta funcion ServerSocket.Socket.ReceiveStream no existe XD .. como puedo hacer? si alguien se le ocurre.

Saludos

Última edición por kdemia fecha: 18-03-2011 a las 19:29:29.
Responder Con Cita
  #2  
Antiguo 18-03-2011
JXJ JXJ is offline
Miembro
 
Registrado: abr 2005
Posts: 2.475
Poder: 22
JXJ Va por buen camino
Cita:
Empezado por kdemia Ver Mensaje
que tal gente, bueno acudo nuevamente a ustedes para que me ayuden en mi problema:
necesito mandar una imagen.. bien?, bueno a la imagen la transformo en un stream y la mando algo asi

Código Delphi [-]ClientSocket.Socket.SendStream(ImgStream)


el tema es que no tengo una manera, o por lo menos la desconosco, de leer el stream, es decir recivirlo algo asi:

Código Delphi [-]Imagen.Picture.Bitmap.Assign(ServerSocket.Socket.ReceiveStream)


pasa que la supuesta funcion ServerSocket.Socket.ReceiveStream no existe XD .. como puedo hacer? si alguien se le ocurre.

Saludos

revisa esta forma de hacerlo


http://www.delphi3000.com/articles/article_2313.asp?SK=

Código Delphi [-]
 
{
Question/Problem/Abstract:
How can I send files using TClientSocket & TServerSocket? 
Sending files with TClientSocket/TServerSocket 
Answer:
 
}
unit Unit1; 
interface 
uses 
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, 
  ScktComp, ExtCtrls, StdCtrls; 
type 
  TForm1 = class(TForm) 
    Image1: TImage; 
    Image2: TImage; 
    ClientSocket1: TClientSocket; 
    ServerSocket1: TServerSocket; 
    Button1: TButton; 
    procedure Image1Click(Sender: TObject); 
    procedure FormCreate(Sender: TObject); 
    procedure ClientSocket1Connect(Sender: TObject; 
      Socket: TCustomWinSocket); 
    procedure ServerSocket1ClientRead(Sender: TObject; 
      Socket: TCustomWinSocket); 
    procedure ClientSocket1Read(Sender: TObject; Socket: TCustomWinSocket); 
  private 
    { Private declarations } 
    Reciving: boolean; 
    DataSize: integer; 
    Data: TMemoryStream; 
  public 
    { Public declarations } 
  end; 
var 
  Form1: TForm1; 
implementation 
{$R *.DFM} 
procedure TForm1.Image1Click(Sender: TObject); 
begin 
  // This is the procedure to open the socket for RECEIVING. 
  // Button1.Click is this procedure as well. 
  ClientSocket1.Active:= true; 
end; 
procedure TForm1.FormCreate(Sender: TObject); 
begin 
  // Open the SENDING socket. 
  ServerSocket1.Active:= true; 
end; 
procedure TForm1.ClientSocket1Connect(Sender: TObject; 
  Socket: TCustomWinSocket); 
begin 
  // Send command to start the file sending. 
  Socket.SendText('send'); 
end; 
procedure TForm1.ClientSocket1Read(Sender: TObject; 
  Socket: TCustomWinSocket); 
var 
  s, sl: string; 
begin 
  s:= Socket.ReceiveText; 
  // If we're not in recieve mode: 
  if not Reciving then 
  begin 
    // Now we need to get the length of the data stream. 
    SetLength(sl, StrLen(PChar(s))+1); // +1 for the null terminator 
    StrLCopy(@sl[1], PChar(s), Length(sl)-1); 
    DataSize:= StrToInt(sl); 
    Data:= TMemoryStream.Create; 
    // Delete the size information from the data. 
    Delete(s, 1, Length(sl)); 
    Reciving:= true; 
  end; 
  // Store the data to the file, until we've received all the data. 
  try 
    Data.Write(s[1], length(s)); 
    if Data.Size = DataSize then 
    begin 
      Data.Position:= 0; 
      Image2.Picture.Bitmap.LoadFromStream(Data); 
      Data.Free; 
      Reciving:= false; 
      Socket.Close; 
    end; 
  except 
    Data.Free; 
  end; 
end; 
procedure TForm1.ServerSocket1ClientRead(Sender: TObject; 
  Socket: TCustomWinSocket); 
var 
  ms: TMemoryStream; 
begin 
  // The client wants us to send the file. 
  if Socket.ReceiveText = 'send' then 
  begin 
    ms:= TMemoryStream.Create; 
    try 
      // Get the data to send. 
      Image1.Picture.Bitmap.SaveToStream(ms); 
      ms.Position:= 0; 
      // Add the length of the data, so the client 
      // will know how much data to expect. 
      // Append #0 so it can determine where the size info stops. 
      Socket.SendText(IntToStr(ms.Size) + #0); 
      // Send it (the socket owns the stream from now on). 
      Socket.SendStream(ms); 
    except 
      // So only free the stream if something goes wrong. 
      ms.Free; 
    end; 
  end; 
end; 
end.
Responder Con Cita
  #3  
Antiguo 19-03-2011
kdemia kdemia is offline
Miembro
 
Registrado: may 2010
Posts: 109
Poder: 14
kdemia Va por buen camino
y en que momento lee el stream en el clientsocket read.. no lo estoy entendiendo muy bien a ese proceso.. y el reciving en que momento se inicializa.. o que valor tiene al principio?
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
tClientSocket, tServerSocket StartKill Varios 5 26-04-2011 21:00:34
TClientSocket y TServerSocket kdemia Internet 2 02-06-2010 21:43:19
TClientSocket / TServerSocket WAN-LAN FunBit Varios 2 27-11-2009 17:41:22
proxy TServerSocket/TClientSocket TROMPO Internet 0 31-03-2008 19:48:35
TClientSocket y TServerSocket fled Internet 10 14-06-2004 08:35:33


La franja horaria es GMT +2. Ahora son las 14:56:14.


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