Delphi - ayuda

 
Vista:

ayuda

Publicado por eddy (8 intervenciones) el 10/08/2006 23:10:53
Hola estoy haciendo una aplicacion cliente - servidor en delphi con serversocket y clientsocket. Pero no se enviar archivos y necesito por favor que alguien me ayude. Muchas gracias deantemano. saludos.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:ayuda

Publicado por BigLuis (713 intervenciones) el 11/08/2006 12:40:08
Por ejemplo en el ServerSocket al recibir una comunicacion del cliente se dispara el evento siguiente:
procedure TForm1.ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
Puedes valorar la peticion del cliente y si esta es enviar un fichero Fichero.bmp o de texto pues puedes escribir lo siguiente
strCommand es la cadena que te manta el cliente

strCommand := Socket.ReceiveText;

else if Pos ('TEXT!', strCommand) = 1 then
begin
if FileExists (strFile) then
begin
strFeedback := 'TEXT!';
Socket.SendText (strFeedback);
Socket.SendStream (TFileStream.Create (
strFile, fmOpenRead or fmShareDenyWrite));
end
else
begin
strFeedback := 'ERROR' + strFile + ' not found';
Socket.SendText (strFeedback);
end;
end

// enviar un fichero bmp
else if Pos ('BITM!', strCommand) = 1 then
begin
if FileExists (strFile) then
begin
strFeedback := 'BITM!';
Socket.SendText (strFeedback);
Socket.SendStream (TFileStream.Create (
strFile, fmOpenRead or fmShareDenyWrite));
end

Suerte
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

Ahora con el cliente

Publicado por BigLuis (713 intervenciones) el 11/08/2006 12:46:41
Y en el cliente al recibir los ficheros los puedes leer asi
si el servidor te manta un fiochero de texto :
type
TCliStatus = (csIdle, csList, csBitmap, csText, csError);
private
CliStatus: TCliStatus;
Buffer: array [0..9999] of Char;

procedure TForm1.ClientSocket1Read(Sender: TObject;
Socket: TCustomWinSocket);
var
strIn: string;
Stream: TMemoryStream;
nReceived: Integer;
begin
case CliStatus of

csText:
begin
with TFormText.Create (Application) do
begin
Memo1.Text := Socket.ReceiveText;
Show;
end;
cliStatus := csIdle;
end;
// leer el bitmap
csBitmap:
with TFormBmp.Create (Application) do
begin
Stream := TMemoryStream.Create;
Screen.Cursor := crHourglass;
try
while True do
begin
nReceived := Socket.ReceiveBuf (Buffer, sizeof (Buffer));
if nReceived <= 0 then
Break
else
Stream.Write (Buffer, nReceived);
Sleep (200); //dale tiempo a que trabaje
end;
// reset y cargar el fichero temporal
Stream.Position := 0;
Image1.Picture.Bitmap.LoadFromStream (Stream);
finally
Stream.Free;
Screen.Cursor := crDefault;
end;

Suerte
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:Ahora con el cliente

Publicado por Eddy (8 intervenciones) el 12/08/2006 21:12:47
muchas gracias BigLuis , lo necesitaba mucho!!!.
saludos.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar