Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2008-09

Send stream whit sockets

3 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Usuario Anónimo

How I can to send a stream whit sockets?

I want to port this Delphi code to Lazarus:

 procedure TForm1.Button2Click(Sender: TObject);
begin
  if ClientSocket1.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
        ClientSocket1.Socket.SendText('FILE!'+Edit1.Text);
        sleep(2000); // Need to sleep so the other end has time to process
the commands
        Streamsize := TFileStream.Create(OpenDialog1.FileName, fmopenread);
// Stream created just to Calculate size
        Edit2.Text := inttostr(Streamsize.Size);
        Sleep(2000);
        ClientSocket1.Socket.SendText('SIZE!'+Edit2.Text); // Sends filesize
through primary socket
        Streamsize.Position := 0;
        Streamsize.Free;
        sleep(2000);
        ClientSocket2.Address := Edit3.Text;
        ClientSocket2.Open; // ready to send file on second socket
        if
ClientSocket2.Socket.SendStream(TFileStream.Create(OpenDialog1.FileName,
fmopenRead)) then memo1.Lines.Add('File Sent');
     // above creates a stream and sends as a stream its in a if line
because this is the only way it will automatically check the byte order and
send the whole stream
     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;

Regards.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.lazarus.freepascal.org/pipermail/lazarus/attachments/20080927/45c31d04/attachment.html

Reply by email

Luca Olivetti
to Usuario Anónimo

En/na Usuario An?nimo ha escrit:

How I can to send a stream whit sockets? I want to port this Delphi code to Lazarus:

It seems that your code uses an ad-hoc protocol to send the file. You could just use synapse and either use the same ad-hoc protocol (a synapse socket has various kinds of Send functions, one of them to send a stream) or use, e.g., tftp (there are routines to handle it already in synapse).

http://ararat.cz/synapse/

Bye

Luca

Reply by email

Usuario Anónimo
to Luca Olivetti

I need that my program works under WinCe... Synapse isn?t supported.

2008/9/27 Luca Olivetti

Show quoted text 24 lines
En/na Usuario An?nimo ha escrit: > How I can to send a stream whit sockets? > > I want to port this Delphi code to Lazarus: It seems that your code uses an ad-hoc protocol to send the file. You could just use synapse and either use the same ad-hoc protocol (a synapse socket has various kinds of Send functions, one of them to send a stream) or use, e.g., tftp (there are routines to handle it already in synapse). http://ararat.cz/synapse/ Bye -- Luca _______________________________________________ Lazarus mailing list http://www.lazarus.freepascal.org/mailman/listinfo/lazarus

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.lazarus.freepascal.org/pipermail/lazarus/attachments/20080928/16186729/attachment-0001.html

Reply by email