Recent

Author Topic: Synapse TFTP file transfer  (Read 15821 times)

rvk

  • Hero Member
  • *****
  • Posts: 7014
Re: Synapse TFTP file transfer
« Reply #45 on: May 29, 2020, 07:05:42 pm »
To (further) clarify, my issue is with pushing from client to server where the server has the smaller buffer..... but you seem to suggest that, in case everything goes well, there shouldn't be a problem. That is reason for me to believe i do still have something erroneously code lurking around  :-\ I was/am not certain about how synapse would approach such situation internally (I'll take a closer look to its implementation details later).
Internal packets of ethernet are already about 1500 bytes. And that's not even the buffer of your program. So packets are send and the sender waits for the acknowledgment. If that doesn't come there is a resend or a timeout at the end of the sender. Packets are not easily lost with tcp. The only thing could be that the sender sometimes needs to wait before the receiver handles the packets. That's what the timeout are for.

And because that's all done by the ethernet driver, you shouldn't have any problems if the sender buffer is smaller. But don't set the timeout at the sender too small.

« Last Edit: May 29, 2020, 07:12:10 pm by rvk »

Jake012345

  • Sr. Member
  • ****
  • Posts: 270
  • Knowledge is the key
Re: Synapse TFTP file transfer
« Reply #46 on: May 30, 2020, 07:06:55 am »
Hello!

How can I get the size of file?

I tried the:

Code: Pascal  [Select][+][-]
  1. var f:file;
  2.     filesize:int64;
  3.  
  4. assignfile(f,filename);
  5. Filesize:=FileUtil.FileSize(f {or filename});
  6. showmessage(filename+IntToStr(filesize));
  7.  

But I can see -1 if I use the filename or 255 if I declared filesize as byte and 288 if I use
Reset(f) before and
4 or 44 if I used SizeOf()
istead FileSize()

(The real size is: 265 MB (278 040 455 byte) )

what is the good code?
« Last Edit: May 30, 2020, 07:37:16 am by Jake012345 »

GAN

  • Sr. Member
  • ****
  • Posts: 389
Re: Synapse TFTP file transfer
« Reply #47 on: May 30, 2020, 07:48:17 am »
Code: Pascal  [Select][+][-]
  1. var f:file of byte;
  2.     filesize:int64;
  3.  
  4. assign(f,filename);
  5. Reset(f);
  6. Filesize:=FileSize(f {or filename});
  7. Close(f);
  8. showmessage(filename+IntToStr(filesize));
  9.  

See https://www.freepascal.org/docs-html/rtl/system/filesize.html
Linux Mint Mate (allways)
Zeos 7̶.̶2̶.̶6̶ 7.1.3a-stable - Sqlite - LazReport

Jake012345

  • Sr. Member
  • ****
  • Posts: 270
  • Knowledge is the key
Re: Synapse TFTP file transfer
« Reply #48 on: May 30, 2020, 08:09:46 am »
I have some more error...

rvk

  • Hero Member
  • *****
  • Posts: 7014
Re: Synapse TFTP file transfer
« Reply #49 on: May 30, 2020, 08:23:49 am »
I have some more error...
Use assignfile and closefile.

Of better yet... just use
Code: Pascal  [Select][+][-]
  1. uses FileUtil;
  2. //...
  3. Filesize := FileUtil.FileSize(filename);

Jake012345

  • Sr. Member
  • ****
  • Posts: 270
  • Knowledge is the key
Re: Synapse TFTP file transfer
« Reply #50 on: May 30, 2020, 08:28:20 am »
I have RunError(2) on Reset(f);

rvk

  • Hero Member
  • *****
  • Posts: 7014
Re: Synapse TFTP file transfer
« Reply #51 on: May 30, 2020, 08:30:09 am »
I have RunError(2) on Reset(f);
Don't use reset, assignfile and closefile.

All you need is
Filesize := FileUtil.FileSize(filename);
Nothing else.

Btw, runtime error 2 is file not found.
So make sure the file exists.

« Last Edit: May 30, 2020, 08:32:08 am by rvk »

Jake012345

  • Sr. Member
  • ****
  • Posts: 270
  • Knowledge is the key
Re: Synapse TFTP file transfer
« Reply #52 on: May 30, 2020, 08:34:19 am »
Thanks!

the runerror 2 was because I used the file name without path...

Jake012345

  • Sr. Member
  • ****
  • Posts: 270
  • Knowledge is the key
Re: Synapse TFTP file transfer
« Reply #53 on: May 30, 2020, 08:49:09 am »
And what commands can I use to write and read stream from a file?
Read/write
or
Read byte/Write byte
or
buffer,ansi string,word?

or enough if I use similar in each parts?

rvk

  • Hero Member
  • *****
  • Posts: 7014
Re: Synapse TFTP file transfer
« Reply #54 on: May 30, 2020, 08:51:06 am »
Use TFileStream.
Examples can be found here
https://wiki.freepascal.org/TFileStream

Jake012345

  • Sr. Member
  • ****
  • Posts: 270
  • Knowledge is the key
Re: Synapse TFTP file transfer
« Reply #55 on: May 30, 2020, 09:34:26 am »
I can't understand this :(

Jake012345

  • Sr. Member
  • ****
  • Posts: 270
  • Knowledge is the key
Re: Synapse TFTP file transfer
« Reply #56 on: May 30, 2020, 09:39:34 am »
how can I test if stream at the end?

rvk

  • Hero Member
  • *****
  • Posts: 7014
Re: Synapse TFTP file transfer
« Reply #57 on: May 30, 2020, 09:48:41 am »
I can't understand this :(
What part don't you understand?
Try to understand it line by line.

how can I test if stream at the end?
You check stream.position against stream.size.

Code: Pascal  [Select][+][-]
  1. while stream.position < stream.size do
  2. begin
  3.   // read from stream
  4. end;

Jake012345

  • Sr. Member
  • ****
  • Posts: 270
  • Knowledge is the key
Re: Synapse TFTP file transfer
« Reply #58 on: May 30, 2020, 09:51:08 am »
I wrote this:
Code: Pascal  [Select][+][-]
  1.   if mode='fileaccept' then begin
  2.    FolderPath.Enabled:=false;
  3.  
  4.     MainStream.Create(infile_name,fmCreate);
  5.     repeat
  6.       if Connection.PeekByte(10)>0 then begin
  7.         Connection.RecvStreamRaw(MainStream,10);
  8.         MainStream.Position:=0;
  9.         MainStream.Write(streambuffer[1],n);
  10.       end;
  11.     until IntToStr(FileUtil.FileSize(infile_name))=infile_size;
  12.     MainStream.free;
  13.  

and this:

Code: Pascal  [Select][+][-]
  1.   MainStream.Create(OpenFileDialog.FileName,fmOpenRead);
  2.   repeat
  3.     streambuffer:='';
  4.     MainStream.Read(streambuffer,MainStream.Size);
  5.     Connection.SendStreamRaw(MainStream);
  6.   until MainStream.;  
  7.  

rvk

  • Hero Member
  • *****
  • Posts: 7014
Re: Synapse TFTP file transfer
« Reply #59 on: May 30, 2020, 10:04:44 am »
Quote
MainStream.Read(streambuffer,MainStream.Size);
You read in the complete MainStream.Size here into the Streambuffer.
So there is no need for a loop because you read the entire stream in one go.
Do note that you'r buffer needs to be big enough for the complete file.

But you have a string as buffer. My first question is... what kind of files are you transfering.
If they are binary you'll need to use an array of bytes as buffer, not a string type.

If they are binary, you can forget about buffers and just do a
Connection.SendStreamRaw(Stream);
and
Connection.RecvStreamRaw(Stream);
without any loop.

Using the SendStreamRaw and RecvStreamRaw, Synapse will internally take care of everything.

Code: Pascal  [Select][+][-]
  1. MainStream.Create(infile_name,fmCreate);
  2. Connection.RecvStreamRaw(MainStream, 60000); // 60 seconds timeout
  3. MainStream.Free;
  4.  

Code: Pascal  [Select][+][-]
  1. MainStream.Create(OpenFileDialog.FileName,fmOpenRead);
  2. Connection.SendStreamRaw(MainStream);
  3. MainStream.Free;
« Last Edit: May 30, 2020, 10:06:48 am by rvk »

 

TinyPortal © 2005-2018