Recent

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

rvk

  • Hero Member
  • *****
  • Posts: 6163
Re: Synapse TFTP file transfer
« Reply #75 on: May 30, 2020, 10:54:17 am »
and the Unable to open file error?
Code and exact error.


Jake012345

  • Sr. Member
  • ****
  • Posts: 270
  • Knowledge is the key
Re: Synapse TFTP file transfer
« Reply #76 on: May 30, 2020, 10:55:15 am »
Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls,
  9.   strutils, FileUtil,
  10.   laz_synapse, blcksock;
  11.  
  12. type
  13.  
  14.   { TForm1 }
  15.  
  16.   TForm1 = class(TForm)
  17.     ChecksumEdit: TEdit;
  18.     FolderPath: TEdit;
  19.     FolderLocateButton: TButton;
  20.     FilePath: TEdit;
  21.     FileLocateButton: TButton;
  22.     FileSendButton: TButton;
  23.     ConnectButton: TButton;
  24.     Log: TMemo;
  25.     OpenFileDialog: TOpenDialog;
  26.     PortEdit: TEdit;
  27.     IpEdit: TEdit;
  28.     HostButton: TButton;
  29.     OpenFolderDialog: TSelectDirectoryDialog;
  30.     RadioButton1: TRadioButton;
  31.     RadioButton2: TRadioButton;
  32.     GetTimer: TTimer;
  33.     procedure ConnectButtonClick(Sender: TObject);
  34.     procedure ChecksumEditChange(Sender: TObject);
  35.     procedure FileLocateButtonClick(Sender: TObject);
  36.     procedure FileSendButtonClick(Sender: TObject);
  37.     procedure FolderLocateButtonClick(Sender: TObject);
  38.     procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
  39.     procedure FormCreate(Sender: TObject);
  40.     procedure HostButtonClick(Sender: TObject);
  41.     procedure RadioButton1Change(Sender: TObject);
  42.     procedure RadioButton2Change(Sender: TObject);
  43.     procedure GetTimerTimer(Sender: TObject);
  44.   private
  45.  
  46.   public
  47.  
  48.   end;
  49.  
  50. var
  51.   Form1: TForm1;
  52.  
  53. implementation
  54.  
  55. {$R *.lfm}
  56.  
  57. { TForm1 }
  58.  
  59. var MainServer:TTCPBlockSocket;
  60.     Connection:TTCPBlockSocket;
  61.     AcceptState:byte=1;
  62.     LogMessage:string;
  63.     connected:boolean;
  64.     filename:string;
  65.     mode:string;
  66.     checksum:string;
  67.     MainStream:TFileStream;
  68.     filesize:integer;
  69.     streambuffer:string;
  70.  
  71. procedure Logging;
  72. begin
  73.   Form1.Log.Lines.Add(LogMessage);
  74.   LogMessage:='';
  75. end;
  76.  
  77. procedure TForm1.FolderLocateButtonClick(Sender: TObject);
  78. begin
  79.   if OpenFolderDialog.execute then FolderPath.Text:=OpenFolderDialog.FileName;
  80.   SetCurrentDir(OpenFolderDialog.FileName);
  81. end;
  82.  
  83. procedure TForm1.FormClose(Sender: TObject; var CloseAction: TCloseAction);
  84. begin
  85.   Halt;
  86. end;
  87.  
  88. procedure TForm1.FormCreate(Sender: TObject);
  89. begin
  90.   mode:='string';
  91. end;
  92.  
  93. procedure TForm1.FileLocateButtonClick(Sender: TObject);
  94.  var f:file;
  95.      s:string;
  96. begin
  97.   if OpenFileDialog.execute then FilePath.Text:=OpenFileDialog.FileName;
  98.   filename:=ExtractDelimited(WordCount(OpenFileDialog.FileName,[DirectorySeparator]),
  99.   OpenFileDialog.FileName,[DirectorySeparator]);
  100.  
  101.   Filesize:=FileUtil.FileSize(OpenFileDialog.FileName);
  102.  
  103.   showmessage(filename+'  '+IntToStr(filesize));
  104. end;
  105.  
  106. procedure TForm1.FileSendButtonClick(Sender: TObject);
  107. begin
  108.   mode:='filesend';
  109.   FilePath.Enabled:=false;
  110.   if connected=true then
  111.   if Connection.CanWrite(10) then
  112.    if checksum<>'' then
  113.      Connection.SendString('>StartSendFile'+':'+filename+':'+IntToStr(filesize)
  114.       +':'+checksum+#13#10)
  115.    else
  116.      Connection.SendString('>StartSendFile'+':'+filename+':'+IntToStr(filesize)+#13#10);
  117.  
  118.   MainStream:=TFileStream.Create(OpenFileDialog.FileName,fmOpenRead);
  119.   MainStream.Create(OpenFileDialog.FileName,fmOpenRead);
  120.   Connection.SendStreamRaw(MainStream);
  121.   MainStream.Free;
  122.   mode:='string';
  123. end;
  124.  
  125. procedure TForm1.ConnectButtonClick(Sender: TObject);
  126. begin
  127.   connection:=TTCPBlockSocket.Create;
  128.   Connection.CreateSocket;
  129.   Connection.Connect(IpEdit.Text,PortEdit.Text);
  130.   if Connection.LastError=0 then begin
  131.     LogMessage:=('Successfully connected to ('+Connection.GetRemoteSinIP+')');
  132.     connected:=true;
  133.   end;
  134.  
  135.   Logging;
  136. end;
  137.  
  138. procedure TForm1.ChecksumEditChange(Sender: TObject);
  139. begin
  140.   checksum:=ChecksumEdit.Text;
  141. end;
  142.  
  143. procedure TForm1.HostButtonClick(Sender: TObject);
  144. begin
  145.   MainServer:=TTCPBlockSocket.Create;
  146.   MainServer.CreateSocket;
  147.   MainServer.Bind(IpEdit.Text,PortEdit.Text);
  148.   MainServer.Listen;
  149.   LogMessage:='Server Run.';
  150.   Logging;
  151.  
  152.   repeat
  153.     case AcceptState of
  154.     0: begin
  155.          Exit;
  156.        end;
  157.  
  158.     1: begin
  159.          Application.ProcessMessages;
  160.          if MainServer.CanRead(100) then begin
  161.            Connection:=TTCPBlockSocket.Create;
  162.            Connection.CreateSocket;
  163.            Connection.Socket:=MainServer.Accept;
  164.            LogMessage:=('Connection accepted from ('+Connection.GetRemoteSinIP+')');
  165.            if LogMessage<>'' then Logging;
  166.            connected:=true;
  167.          end;
  168.        end;
  169.  
  170.     end;
  171.  
  172.   until false;
  173. end;
  174.  
  175. procedure TForm1.RadioButton1Change(Sender: TObject);
  176. begin
  177.   if RadioButton1.Checked=true then AcceptState:=1;
  178. end;
  179.  
  180. procedure TForm1.RadioButton2Change(Sender: TObject);
  181. begin
  182.   if RadioButton1.Checked=true then AcceptState:=0;
  183. end;
  184.  
  185. procedure TForm1.GetTimerTimer(Sender: TObject);
  186.  var messagein:String;
  187.      infile_name:string;
  188.      infile_size:string;
  189.      infile_checksum:string;
  190.      f:file;
  191.      n:integer;
  192. begin
  193.   //TEXT MODE
  194.  if connected then begin
  195.  
  196.     if mode='string' then begin
  197.        messagein:=Connection.RecvString(10);
  198.     if (messagein<>'') and (messagein[1]<>'>') then begin
  199.      LogMessage:=messagein;
  200.       Logging;
  201.     end
  202.     else
  203.       if (messagein<>'') and (messagein[1]='>') then begin
  204.           mode:='fileaccept';
  205.  
  206.           infile_name:=ExtractDelimited(2,messagein,[':']);
  207.           infile_size:=ExtractDelimited(3,messagein,[':']);
  208.           infile_checksum:=ExtractDelimited(4,messagein,[':']);
  209.  
  210.           LogMessage:='Accepting file: '+infile_name+' Size: '+
  211.            infile_size+' Checksum: '+infile_checksum;
  212.           logging;
  213.         end;
  214.   end;
  215.   //FILE MODE
  216.   if mode='fileaccept' then begin
  217.    FolderPath.Enabled:=false;
  218.  
  219.    MainStream:=TFileStream.Create(infile_name,fmCreate);
  220.    MainStream.Create(infile_name,fmCreate);
  221.    Connection.RecvStreamRaw(MainStream, 10);
  222.    MainStream.Free;
  223.    mode:='string';
  224.  
  225.   end;
  226.  
  227.  
  228.  end;
  229. end;
  230.  
  231.  
  232. end.
  233.  
  234.  

Jake012345

  • Sr. Member
  • ****
  • Posts: 270
  • Knowledge is the key
Re: Synapse TFTP file transfer
« Reply #77 on: May 30, 2020, 10:55:50 am »
But that's happening on txt files too.

rvk

  • Hero Member
  • *****
  • Posts: 6163
Re: Synapse TFTP file transfer
« Reply #78 on: May 30, 2020, 10:59:32 am »
You still have the lines
MainStream.Create(...
On line 119 and 220.
Remove them. You should never call Create directly on a variabele. Create should obly be called a classtype (for assigment).

Jake012345

  • Sr. Member
  • ****
  • Posts: 270
  • Knowledge is the key
Re: Synapse TFTP file transfer
« Reply #79 on: May 30, 2020, 11:01:45 am »
I deleted the second creation lines and it's working!

Thanks!!

But why?:
Quote
You should never call Create directly on a variabele. Create should obly be called a classtype (for assigment).

rvk

  • Hero Member
  • *****
  • Posts: 6163
Re: Synapse TFTP file transfer
« Reply #80 on: May 30, 2020, 11:04:54 am »
 8)
But why?:
Quote
You should never call Create directly on a variabele. Create should obly be called a classtype (for assigment).
Beause Create is a constructor.
When creating an object, you call a Constructor method of the class, not the object:
 
objectName := ClassName.Create(parms);

Also see http://www.delphibasics.co.uk/RTL.asp?Name=Constructor

Btw. It's the same for
connection:=TTCPBlockSocket.Create
Which you did properly :)

Jake012345

  • Sr. Member
  • ****
  • Posts: 270
  • Knowledge is the key
Re: Synapse TFTP file transfer
« Reply #81 on: May 30, 2020, 11:29:12 am »
I started a transfer ... with 5GB VBox .vdi file...

and somehow I got this code on log:

Code: C  [Select][+][-]
  1. Successfully connected to (127.0.0.1)
  2. Accepting file: windows32.vdi Size: 1075838976 Checksum: 998868565767
  3. A disk read error occurred
  4. NTLDR is missing
  5. NTLDR is compressed
  6. Press Ctrl+Alt+Del to restart
  7. <HTML>
  8. <HEAD>
  9. <OBJECT ID=pchealth classid=CLSID:FC7D9E02-3F9E-11d3-93C0-00C04F72DAF7></OBJECT>
  10. <TITLE>Start Application in Compatibility Mode</TITLE>
  11. <META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=windows-1252">
  12. <META HTTP-EQUIV=PICS-Label CONTENT='(PICS-1.1 "http://www.rsac.org/ratingsv01.html" l comment "RSACi North America Server" by "inet@microsoft.com" r (n 0 s 0 v 0 l 0))'>
  13. <META HTTP-EQUIV="MSThemeCompatible" CONTENT="Yes">
  14. <META content=en-us http-equiv=Content-Language>
  15. <LINK ID=Stylesheet_Ref0 href="hcp://system/css/shared.css"    rel=STYLESHEET type=text/css>
  16. <LINK ID=Stylesheet_Ref1 href="hcp://system/css/Behaviors.css" rel=STYLESHEET type=text/css>
  17. <LINK ID=Stylesheet_Ref2 href="hcp://system/css/Layout.css"    rel=STYLESHEET type=text/css>
  18. <SCRIPT language="javascript">
  19. <!--
  20. var g_sApplicationLocation;    // folder where the app is to be found
  21. var g_sApplicationDisplayName; // display (friendly) name for an application
  22. var g_sApplication;  // application to run(full path)
  23. var g_sPersistPath;  // persist path for this item
  24. var g_sCompatLayer;  // layer to run (string)
  25. var g_sLayerDescription;
  26. var g_sCmdLine;
  27. var g_nPage  = 0;         // current page
  28. var g_nPages = 10;
  29. var g_nStartPage = 0;
  30. var g_rgPages = new Array(g_nPages);
  31. var g_shell   = new ActiveXObject("Wscript.Shell");
  32. var g_fso     = new ActiveXObject("Scripting.FileSystemObject");
  33. var g_bProgramsPopulated = false;
  34. var g_bAppBrowseProgsInitialized = false;
  35. var g_bProgListSelect = false;
  36. var g_util    = new ActiveXObject("CompatUI.Util");
  37. var g_ProgramSelectMethod; // will be
  38. var g_upload = null; // global upload object
  39. var g_UnknownLayers; // unknown layers for the item
  40. var g_bSendReport; // controls whether we send the report or not
  41. var g_bUpdateLayers; // controls whether we set the layers permanently
  42. g_rgPages[0] = 'Intro';
  43. g_rgPages[1] = 'AppSelectMethod';
  44. g_rgPages[2] = 'AppProgramList';
  45. g_rgPages[3] = 'AppBrowseProgs';
  46. g_rgPages[4] = 'FixesLayers';
  47. g_rgPages[5] = 'FixesOther';
  48. g_rgPages[6] = 'Run';
  49. g_rgPages[7] = 'Update';
  50. g_rgPages[8] = 'CompatibilityData';
  51. g_rgPages[9] = 'CompleteWizard';
  52. var g_cIntroPage              = 0;
  53. var g_cAppPage                = 1;
  54. var g_cAppProgramListPage     = 2;
  55. var g_cAppBrowseProgsPage     = 3;
  56. var g_cFixesLayersPage        = 4;
  57. var g_cFixesOtherPage         = 5;
  58. var g_cRunPage                = 6;
  59. var g_cUpdatePage             = 7;
  60. var g_cCompatibilityDataPage  = 8;
  61. var g_cCompleteWizardPage     = 9;
  62. var g_cSelectFromList  = 0;
  63. var g_cSelectRunFromCD = 1;
  64. var g_cSelectBrowse    = 2;
  65. //////////////////////////////////////////////////////////////////////////////////////
  66. //
  67. // Localization
  68. //
  69. var L_strBtnBackCaption_Button           = '&nbsp;&lt;&nbsp;<u>B</u>ack&nbsp;'; // this is the caption for Back button : ' < Back '
  70. var L_strBtnNextCaption_Button           = '&nbsp;N<u>e</u>xt&nbsp;&gt;&nbsp;'; // this is the caption for Next button : ' Next > '
  71. var L_strBtnFinish_Button                = '&nbsp;<u>F</u>inish&nbsp;';         // this is the caption for Finish button
  72. var L_strStopBtnCaption_Button           = '&nbsp;Sto<u>p</u>&nbsp;';
  73. var L_strRefreshBtnCaption_Button        = '&nbsp;<u>R</u>efresh&nbsp;';
  74. var L_strCancelBtnCaption_Button         = '&nbsp;Cancel&nbsp;';
  75. var L_strBrowseBtnCaption_Button         = 'Bro<u>w</u>se';
  76. var L_strPage2Accelerators_Text          = 'RSPEB';     //  Attention, localizers: this parameter should be localized and match accelerators on this page
  77.                                                         //  R = Refresh S = Select P - stoP E - nExt B - Back -->
  78.                                                         //  see page 2 below for Select, all the others have to match the buttons above
  79. var L_strPage3Accelerators_Text          = 'YEB';       //  Attention localizers: this parameter should be localized and match accelerators on this page
  80.                                                         //  Y = tYpe E - nExt B - Back
  81.                                                         //  except for the browse button
  82. var L_strCompatSettingsAdjusted_Text   = 'You have successfully adjusted the compatibility settings for this program.';
  83. var L_strCompatSettingsNotAdjusted_Text= 'Compatibility settings were not changed for any programs.';
  84. var L_strBrowseFilter_Text             = 'Program files (*.exe;*.com;*.pif;*.cmd;*.bat;*.lnk)|*.exe;*.com;*.pif;*.cmd;*.bat;*.lnk|All files (*.*)|*.*';
  85. var L_strBrowseCaption_DialogTitle     = 'Please Select Application';
  86. var L_strBrowseProgsLabel_Text         = 'T<U>y</U>pe the path to the program shortcut or executable file:';
  87. var L_rgExcludeFiles_FileName         = new Array('%ProgramFiles%\\Windows NT\\hypertrm.exe',
  88.                                                   '%programfiles%\\msn\\msncorefiles\\msn6.exe',
  89.                                                   '%programfiles%\\messenger\\msmsgs.exe',
  90.                                                   '%SystemRoot%\\system32\\notepad.exe');
  91. var L_strCompatModeRemovableMedia_Text = '<b>Warning:</b> &nbsp;&nbsp; Compatibility mode cannot be set on this program. &nbsp; The selected program is on the network or a removable media device.';
  92. var L_strCompatModePartOfOS_Text       = '<b>Warning:</b> &nbsp;&nbsp; Compatibility Mode cannot be set on this program. &nbsp; Selected program is part of the Operating System.';
  93. var L_strCompatModeNotExe_Text         = '<b>Warning:</b> &nbsp;&nbsp; Compatibility Mode cannot be set on this object.  &nbsp; Selected object is not a program executable file.';
  94. var L_strFileOnTheNet_Text             = '<br>Warning: &nbsp;&nbsp; this file is on removable media or on the network';
  95. var L_strProgramWorked_Text            = '<u>Y</u>es, this program worked correctly';
  96. var L_strProgramWorkedTitle_Text       = 'Yes, this program worked correctly';
  97. var L_strSetPermanentLayers_Text       = '<u>Y</u>es, set this program to always use these compatibility settings';
  98. var L_strSetPermanentLayersTitle_Text  = 'Yes, set this program to always use these compatibility settings';
  99. var L_strNoCompatSettings_Text         = 'No compatibility settings were selected.';
  100. var L_strRetryCD_Message               = 'Wizard could not locate programs on your CD\nClick OK to retry, Cancel to try and locate the program manually';
  101. var L_strSpecifyValidApp_Message       = 'Please specify a valid program';
  102. var L_strChooseProgram_Message         = 'Please choose a program from the list';
  103. var L_strErrorUpdatingShortcut_ErrorMessage    = 'Error Updating application shortcut for ';
  104. var L_strAppNotFound_ErrorMessage              = 'Target Application Not Found!\n\nThe file path is invalid:  ';
  105. var L_strEnsureExist_ErrorMessage              = '\n\nEnsure that you have entered the full and correct path to the target application.\n';
  106. var L_strMustValid_ErrorMessage                = 'The application path must point to a valid Program or Shortcut file.';
  107. var L_strErrorStartingApp_ErrorMessage         = 'Error starting program:\n\n';
  108. var L_rgSetupPrograms_FileName = new Array(4); // this array contains the names of setup programs
  109. L_rgSetupPrograms_FileName[0] = 'setup.cmd';   // this array should not be touched but some more
  110. L_rgSetupPrograms_FileName[1] = 'setup.bat';   // (localized) entries may be added
  111. L_rgSetupPrograms_FileName[2] = 'setup.exe';
  112. L_rgSetupPrograms_FileName[3] = 'install.exe';
  113. //
  114. // these idcs correspond to ids of internal controls in appcompat\compatui.dll
  115. //
  116. var g_cIDC_EDITFILENAME = 207;
  117. var g_cIDC_BROWSE       = 208;
  118. ///////////////////////////////////////////////////////////////////////////////////
  119. //
  120. // Initialize global objects (compatUI)
  121. //
  122. function InitCompatUIObjects() {
  123.     var BrowseProgs = document.all['BrowseProgs'];
  124.     var ProgList    = document.all['SelectProgs'];
  125.     var lblBrowse   = document.all['lblBrowseProgs'];
  126.     var sExclude = '';
  127.     var i;
  128.     for (i = 0; i < L_rgExcludeFiles_FileName.length; ++i) {
  129.         if (i > 0) {
  130.             sExclude += ';';
  131.         }
  132.         sExclude += L_rgExcludeFiles_FileName[i];
  133.     }
  134.     ProgList.ExcludeFiles        = sExclude;
  135.     ProgList.ExternAccel         = L_strPage2Accelerators_Text;
  136.     lblBrowse.innerHTML          = L_strBrowseProgsLabel_Text;
  137.     lblBrowse.accessKey          = GetAccessKeyFromCaption(L_strBrowseProgsLabel_Text);
  138.     BrowseProgs.AccelCmd(g_cIDC_EDITFILENAME) = GetAccessKeyFromCaption(L_strBrowseProgsLabel_Text);
  139.     BrowseProgs.ExternAccel      = L_strPage3Accelerators_Text;
  140.     BrowseProgs.BrowseBtnCaption = L_strBrowseBtnCaption_Button;
  141.     BrowseProgs.accessKey        = GetAccessKeyFromCaption(L_strBrowseBtnCaption_Button);
  142. }
  143. function checkRadio(ctlName, choiceValue) {
  144.     var collection;
  145.     var i;
  146.     collection = document.all[ctlName];
  147.     for (i = 0; i < collection.length; i++) {
  148.         if (collection[i].value.toUpperCase() == choiceValue.toUpperCase()) {
  149.             collection[i].checked = true;
  150.             return;
  151.         }
  152.     }
  153. }
  154. function getRadioText(ctlName, selValue) {
  155.     var collection;
  156.     var i;
  157.     var lblName;
  158.     var vLabel;
  159.     collection = document.all[ctlName];
  160.     for (i = 0; i < collection.length; i++) {
  161.         if (collection[i].value.toUpperCase() == selValue.toUpperCase()) {
  162.             lblName = 'lbl' + collection[i].value;
  163.             vLabel = document.all[lblName];
  164.             return(vLabel.innerText);
  165.         }
  166.     }
  167. }
  168. function getRadioValue(ctlName) {
  169.     var collection;
  170.     var i;
  171.     collection = document.all[ctlName];
  172.     for (i = 0; i < collection.length; i++) {
  173.         if (collection[i].checked) {
  174.             return(collection[i].value);
  175.         }
  176.     }
  177. }
  178. function checkCheckbox(ctlName, bCheck) {
  179.     var ctl = document.all[ctlName];
  180.     ctl.checked = bCheck;
  181. }
  182. function getCheckValue(ctlName) {
  183.     var ctl = document.all[ctlName];
  184.     if (ctl.checked == true) {
  185.         return ctl.value;
  186.     }
  187.     return null;
  188. }
  189. function getCheckText(selValue) {
  190.     var lblName = 'lbl' + selValue;
  191.     var vLabel = document.all[lblName];
  192.     if (vLabel != null) {
  193.         return vLabel.innerText;
  194.     }
  195.     //
  196.     // this means we have no text -- "unknown" value
  197.     //
  198.     return '(' + selValue + ')';
  199. }
  200. function ShowDiv(divName, bShow) {
  201.     var div = document.all[divName];
  202.     if (bShow) {
  203.         // alert('Show ' + divName);
  204.         div.style.display = '';
  205.     } else {
  206.         // alert('Hide ' + divName);
  207.         div.style.display = 'none';
  208.     }
  209. }
  210. function InitPage() {
  211.     for (i = 0; i < g_rgPages.length; ++i) {
  212.         ShowDiv(g_rgPages[i], g_nStartPage == i);
  213.     }
  214.     // init common buttons (cancel)
  215.     var btnCancel = document.all('btnCancel');
  216.     btnCancel.innerHTML = L_strCancelBtnCaption_Button;
  217.     InitCompatUIObjects();
  218.     Intro_InitPage();
  219.     // init global vars - no further init
  220. }
  221. function GetAccessKeyFromCaption(sCaption) {
  222.     var sUTag  = '<u>';
  223.     var sUCTag = '</u>';
  224.     var sAccessKey = '';
  225.     var sCaplc = sCaption.toLowerCase();
  226.     var ixU = sCaplc.indexOf(sUTag);
  227.     if (ixU < 0) {
  228.         return sAccessKey;
  229.     }
  230.     var ixCU = sCaplc.indexOf(sUCTag, ixU);
  231.     if (ixCU < 0) {
  232.         return sAccessKey;
  233.     }
  234.     // get the string between the tags
  235.     sAccessKey = sCaplc.substring(ixU + sUTag.length, ixCU);
  236.     sAccessKey.toUpperCase();
  237.     return sAccessKey;
  238. }
  239. function InitNavButtons(bBackEnabled, sNextButtonValue) {
  240.     var frmNav = document.forms('frmNav');
  241.     var btnBack = frmNav('btnBack');
  242.     btnBack.innerHTML = L_strBtnBackCaption_Button;
  243.     btnBack.accessKey = GetAccessKeyFromCaption(L_strBtnBackCaption_Button);
  244.     btnBack.disabled = !bBackEnabled;
  245.     var btnNext = frmNav('btnNext');
  246.     btnNext.disabled = false;
  247.     if (null != sNextButtonValue) {
  248.         btnNext.innerHTML = sNextButtonValue;
  249.     } else {
  250.         btnNext.innerHTML = L_strBtnNextCaption_Button;
  251.     }
  252.     btnNext.accessKey = GetAccessKeyFromCaption(btnNext.innerHTML);
  253.     btnNext.focus();
  254. }
  255. //
  256. // selected flags
  257. //
  258. var OFN_HIDEREADONLY       = 0x00000004;
  259. var OFN_PATHMUSTEXIST      = 0x00000800;
  260. var OFN_FILEMUSTEXIST      = 0x00001000;
  261. var OFN_EXPLORER           = 0x00080000;   // new look commdlg
  262. var OFN_NODEREFERENCELINKS = 0x00100000;   // prevents a link from being cracked
  263. var OFN_ENABLESIZING       = 0x00800000;
  264. var OFN_FORCESHOWHIDDEN    = 0x10000000;    // Show All files including System and hidden files
  265. var g_ofnFlags = OFN_HIDEREADONLY|
  266.                  OFN_PATHMUSTEXIST|
  267.                  OFN_FILEMUSTEXIST|
  268.                  OFN_NODEREFERENCELINKS;
  269. //
  270. // ====================== Page Init Code ====================================
  271. //
  272. //
  273. function Intro_InitPage(nPageFrom) {
  274.     InitNavButtons(false, null);
  275. }
  276. function ProgListAction() {
  277.     var btnAction = document.all['btnProgListAction'];
  278.     switch(btnAction.name) {
  279.     case 'Cancel':
  280.         CancelProgScan();
  281.         break;
  282.     case 'Scan':
  283.         RefreshProgs();
  284.         break;
  285.     }
  286. }
  287. function SetProglistAction(proglistAction) {
  288.     var btnAction = document.all['btnProgListAction'];
  289.     btnAction.name = proglistAction;
  290.     switch(proglistAction) {
  291.     case 'Cancel':
  292.         btnAction.innerHTML = L_strStopBtnCaption_Button;
  293.         break;
  294.     case 'Scan':
  295.         btnAction.innerHTML = L_strRefreshBtnCaption_Button;
  296.         break;
  297.     }
  298.     btnAction.accessKey = GetAccessKeyFromCaption(btnAction.innerHTML);
  299. }
  300. function BlockNextButton(bBlock) {
  301.     var frmNav = document.forms('frmNav');
  302.     var btnNext = frmNav('btnNext');
  303.     var btnBack = frmNav('btnBack');
  304.     if (bBlock) {
  305.         btnBack.focus();
  306.     }
  307.     btnNext.disabled = bBlock; // bummer, next is disabled
  308.     if (!bBlock) {
  309.         btnNext.focus();
  310.     }
  311. }
  312. function AppProgramList_InitPage(nPageFrom) {
  313.     var SelectProgs = document.all['SelectProgs'];
  314.     var BrowseProgs = document.all['BrowseProgs'];
  315.     BrowseProgs.Enabled = false;
  316.     BrowseProgs.Valid   = false;
  317.     SelectProgs.Enabled = true;
  318.     SelectProgs.Valid   = true;
  319.     InitNavButtons(true, null);
  320.     if (!g_bProgramsPopulated) {
  321.         BlockNextButton(true);
  322.         SetProglistAction('Cancel');
  323.     } else {
  324.         SetProglistAction('Scan');
  325.     }
  326. }
  327. function CancelProgScan() {
  328.     var SelectProgs = document.all['SelectProgs'];
  329.     SelectProgs.CancelPopulateList();
  330. }
  331. function RefreshProgs() {
  332.     var SelectProgs = document.all['SelectProgs'];
  333.     var btnNext = document.all['btnNext'];
  334.     BlockNextButton(true);
  335.     SetProglistAction('Cancel');
  336.     SelectProgs.PopulateList();
  337. }
  338. function AppBrowseProgs_InitPage(nPageFrom) {
  339.     var BrowseProgs = document.all['BrowseProgs'];
  340.     var oShell = new ActiveXObject('Shell.Application');
  341. // DEBUGDEBUG
  342.     var SelectProgs = document.all['SelectProgs'];
  343.     SelectProgs.Enabled = false;
  344.     SelectProgs.Valid   = false;
  345.     BrowseProgs.Enabled = true;
  346.     BrowseProgs.Valid   = true;
  347. // localization
  348.     BrowseProgs.BrowseFilter = L_strBrowseFilter_Text;
  349.     BrowseProgs.BrowseFlags  = g_ofnFlags;
  350.     BrowseProgs.BrowseTitle  = L_strBrowseCaption_DialogTitle;
  351.     var shFolder = oShell.Namespace(0x2); // ssPrograms, Folder2 object
  352.     BrowseProgs.BrowseInitialDirectory = shFolder.Self.Path; // convert to folder item and get path
  353.     InitNavButtons(true, null);
  354. }
  355. function Page_NavigateComplete(nPageTo) {
  356.     if (nPageTo == g_cAppBrowseProgsPage) {
  357.         if (g_bAppBrowseProgsInitialized) {
  358.             OnBrowseProgsReady();
  359.         }
  360.     }
  361. }
  362. function OnBrowseProgsReady() {
  363.     var BrowseProgs = document.all['BrowseProgs'];
  364.     BrowseProgs.focus();
  365. }
  366. function AppSelectMethod_InitPage(nPageFrom) {
  367.     InitNavButtons(true, null);
  368. }
  369. function FixesLayers_InitPage(nPageFrom) {
  370.     var sCompatLayer;
  371.     if (nPageFrom < g_cFixesLayersPage) {  // we want to find whether it is a motion forward or backwards
  372.         sCompatLayer = GetApplicationLayer();
  373.         ParseLayers(sCompatLayer);
  374.  
  375.  

And immediately appeared the file in target folder. It was 320KB big and no change. But the code is constantly written and later the program that accept the file freezing with an error :

"" cant create the file       ?!?!! what? I saw the file it was 320KB !  ??

Jake012345

  • Sr. Member
  • ****
  • Posts: 270
  • Knowledge is the key
Re: Synapse TFTP file transfer
« Reply #82 on: May 30, 2020, 11:29:32 am »
The first 2 line is mine

rvk

  • Hero Member
  • *****
  • Posts: 6163
Re: Synapse TFTP file transfer
« Reply #83 on: May 30, 2020, 11:36:23 am »
Quote
Successfully connected to (127.0.0.1)
Are you trying this on the same computer?

Quote
"" cant create the file       ?!?!! what? I saw the file it was 320KB !  ??
Why is there ""
What is the exact error?
Is the filename known on the receiving end?
There was no file on the target with the same name yet?
Does this also happen with a smaller file?

Jake012345

  • Sr. Member
  • ****
  • Posts: 270
  • Knowledge is the key
Re: Synapse TFTP file transfer
« Reply #84 on: May 30, 2020, 11:44:28 am »
yes,
idk,
idk,
Yes,
no,
no.

Jake012345

  • Sr. Member
  • ****
  • Posts: 270
  • Knowledge is the key
Re: Synapse TFTP file transfer
« Reply #85 on: May 30, 2020, 11:58:40 am »
2 GB happens the same
~1.5 GB the sender freezing

rvk

  • Hero Member
  • *****
  • Posts: 6163
Re: Synapse TFTP file transfer
« Reply #86 on: May 30, 2020, 12:00:13 pm »
What happens if you increase the timeout on receive.

Code: Pascal  [Select][+][-]
  1. Connection.RecvStreamRaw(MainStream, 60000); // 60 seconds timeout for receiving

And was that log on thew receiving end or the sending end?
If it was on the receiving end then that's normal. You switched to string mode after the error (can't create) and what's in the buffer on the sending side is still send (so ends up in the receiving log).

BTW, you are doing this with two separate programs running, are you not.
You can't do this in the same program because you then are using the same thread for sending and receiving. And you can't do that without multiple threads.

So start two instances of your program and then try it.

You could also build in a delay of 1 second on the FileSendButtonClick() just before the SendStreamRaw so the receiver has time to setup it's buffers for receiving. Now with the timeout of 60 seconds that may not be needed be also here, better to be safe then sorry.
« Last Edit: May 30, 2020, 12:04:09 pm by rvk »

Jake012345

  • Sr. Member
  • ****
  • Posts: 270
  • Knowledge is the key
Re: Synapse TFTP file transfer
« Reply #87 on: May 30, 2020, 12:07:09 pm »
Quote
What happens if you increase the timeout on receive.
Code: Pascal  [Select][+][-]
  1. Connection.RecvStreamRaw(MainStream, 60000); // 60 seconds timeout for receiving
  2.  


Now with 1,5 GB is working

Jake012345

  • Sr. Member
  • ****
  • Posts: 270
  • Knowledge is the key
Re: Synapse TFTP file transfer
« Reply #88 on: May 30, 2020, 03:47:08 pm »
And how can I use threads?

(I saw the examples on wiki, but I just need the basic's basic)
create,
execute,
destroy.

And I really need to add it to classes?
(I never did that)

rvk

  • Hero Member
  • *****
  • Posts: 6163
Re: Synapse TFTP file transfer
« Reply #89 on: May 30, 2020, 04:11:02 pm »
threads is a lot more difficult.
It isn't going to be much easier then shown here
https://wiki.lazarus.freepascal.org/Multithreaded_Application_Tutorial

But you might see if you can do it (progress) without threads.

Create a new ttimer (with 1000 interval).
If you execute the recvstreamraw... Is that new ttimer still executed?
You can check this by adding some logging in it.

If so, then you can program the progress in that ttimer.
If not, then you'll indeed need to go to threads.


 

TinyPortal © 2005-2018