binarydigit0101 Posted March 9, 2011 Share Posted March 9, 2011 hi all! so, i want to send a file with TCP. i read some posts and i knew i have to use File properties. here's my code: $binaryfile = FileOpen("dati.txt",16) ; open the file binary mode TCPSend($socket,$binaryfile) ; send the binary data to client ; the client instead $file = TCPRecv($socket, 2048) ; receive the file FileWrite($file, "prova.txt") ; write the data into a file what's my error? thank you for all, see you! ;-) ehi ehi ehi, what is your name? Link to comment Share on other sites More sharing options...
jvanegmond Posted March 9, 2011 Share Posted March 9, 2011 ; the client instead $file = TCPRecv($socket, 2048) ; receive the file FileWrite($file, "prova.txt") ; write the data into a file Should be: ; the client instead $file = TCPRecv($socket, 2048) ; receive the file FileWrite("prova.txt", $file) ; write the data into a file github.com/jvanegmond Link to comment Share on other sites More sharing options...
binarydigit0101 Posted March 9, 2011 Author Share Posted March 9, 2011 hahaha! you're right; now the client creates the file. anyway there's another problem: server sends nothing to client. two programs are already connected. what is happening? :-P ehi ehi ehi, what is your name? Link to comment Share on other sites More sharing options...
jvanegmond Posted March 9, 2011 Share Posted March 9, 2011 Make sure that "dati.txt" exists on the server. Otherwise, we will have to see more of your code to determine the problem. github.com/jvanegmond Link to comment Share on other sites More sharing options...
binarydigit0101 Posted March 9, 2011 Author Share Posted March 9, 2011 file is in workdirectory, isn't right? anyway here there is all my code: expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <INet.au3> ; genera il form con tutti i suoi controlli; $Form1 = GUICreate("Accesso remoto!", 370, 450, 192, 124) $pdc = GUICtrlCreateLabel("Pannello di Controllo - Connesso a: NESSUNO [IP INS'T DEFINED].", 24, 16, 326, 17) $attdisatt = GUICtrlCreateButton("Apri il lancia comandi (on)", 24, 56, 150, 33) $pdm = GUICtrlCreateList("", 24, 112, 321, 273) GUICtrlSetData(-1, "Disattivo!") GUICtrlSetState(-1, $GUI_DISABLE) $chiusura = GUICtrlCreateButton("Termina la sessione.", 184, 400, 161, 33) GUISetState(@SW_SHOW) TCPStartup() ; attivo il servizio TCP $ascolto = TCPListen(@IPAddress1, 666) ; mi metto in ascolto sulla porta 666 dell'ip locale While 666 $socket = TCPAccept($ascolto) ; attendo che il client si connetta If $socket <> -1 Then ; quando il client è connesso $ricvo = TCPRecv($socket, 32) ; ricevo la stringa (nome utente e indirizzo ip) $ricv = StringStripWS($ricvo, 1+2) $arrayricv = StringSplit($ricv, "-") $nomeutente = $arrayricv[1] $indirizzoip = $arrayricv[2] $indirizzopubblico = _GetIP() GUICtrlSetData($pdc, "Pannello di Controllo - Connesso a: " & $nomeutente & " [" & $indirizzopubblico & "].") ; ...e imposto i dati ricevuti $binaryfile = FileOpen("dati.txt",16) MsgBox(0, "", $binaryfile) TCPSend($socket,$binaryfile) EndIf $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $chiusura Exit Case $attdisatt GUICtrlSetState($pdm, $GUI_ENABLE) GUICtrlSetData($attdisatt, "Chiudi il lancia comandi (off)") EndSwitch WEnd this's for the client: #include <_TCPFileTransfer.au3> #include <File.au3> TCPStartup() $socket = TCPConnect(@IPAddress1, 666) If $socket <> -1 Then $identify = @UserName & "-" & @IPAddress1 TCPSend($socket, $identify) Else MsgBox(0, "Errore nr: ", @error) EndIf $file = TCPRecv($socket, 2048) MsgBox(0, "ecco il relativo codice:", $file) FileWrite("prova.txt", $file) ehi ehi ehi, what is your name? Link to comment Share on other sites More sharing options...
jvanegmond Posted March 9, 2011 Share Posted March 9, 2011 TCP functions are non-blocking. It means they will return (almost) instantly. Even if there is no data available. Your server code can take a while to execute, during which time the client has already decided there won't be any data. Do something like: While 1 $file = TCPRecv($socket, 2048) MsgBox(0, "ecco il relativo codice:", $file) FileWrite("prova.txt", $file) WEnd github.com/jvanegmond Link to comment Share on other sites More sharing options...
binarydigit0101 Posted March 9, 2011 Author Share Posted March 9, 2011 thank you! sorry but client doesn't receive anything. ehi ehi ehi, what is your name? Link to comment Share on other sites More sharing options...
binarydigit0101 Posted March 9, 2011 Author Share Posted March 9, 2011 thank you! sorry but client doesn't receive anything. Do i put "while" also in server? ehi ehi ehi, what is your name? Link to comment Share on other sites More sharing options...
jvanegmond Posted March 9, 2011 Share Posted March 9, 2011 TCP does not combine easily with GUI. Especially if this is your first time. Remove bits from your script until you have found the problem. It's called debugging and it's a necessary skill for programming. Another mistake: $binaryfile = FileOpen("dati.txt",16) MsgBox(0, "", $binaryfile) TCPSend($socket,$binaryfile What does the MsgBox print? Right ... github.com/jvanegmond Link to comment Share on other sites More sharing options...
binarydigit0101 Posted March 9, 2011 Author Share Posted March 9, 2011 (edited) so the MSGBOX was a way to see what client received. what do i remove for the first times? p.s.: for debug i asked because i don't know if the syntax is correct. Edited March 9, 2011 by binarydigit0101 ehi ehi ehi, what is your name? Link to comment Share on other sites More sharing options...
guinness Posted March 9, 2011 Share Posted March 9, 2011 Maybe these Function will shed some light too. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
binarydigit0101 Posted March 9, 2011 Author Share Posted March 9, 2011 i read something about it, but i do anything. do it need a "include" istruction with a macro? what's this? how can i use this? thank you very much, have a good day! :-) ehi ehi ehi, what is your name? Link to comment Share on other sites More sharing options...
guinness Posted March 9, 2011 Share Posted March 9, 2011 I take it you read the Forum Post, because there is an Example of how to use the Functions in your Script >> I am a little confused by this "do it need a "include" istruction with a macro? what's this? how can i use this?" The Functions have to be copied to your Script and then "Called" when required. As I said have a look at the "Working Example" above to get an idea of how to use UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
binarydigit0101 Posted March 9, 2011 Author Share Posted March 9, 2011 Maybe these Function will shed some light too.LOL! i don't see this was a link... :-Dsorry for this... thank you for all! ;-) ehi ehi ehi, what is your name? Link to comment Share on other sites More sharing options...
Newb Posted March 9, 2011 Share Posted March 9, 2011 u italian? I'm a compulsive poster. When I post something, come to read it at least 5 minutes later after the posting, because I will edit it. I edited even this signature a few minutes later after I wrote it. Link to comment Share on other sites More sharing options...
binarydigit0101 Posted March 9, 2011 Author Share Posted March 9, 2011 oui! ehi ehi ehi, what is your name? Link to comment Share on other sites More sharing options...
Newb Posted March 9, 2011 Share Posted March 9, 2011 pure io I'm a compulsive poster. When I post something, come to read it at least 5 minutes later after the posting, because I will edit it. I edited even this signature a few minutes later after I wrote it. Link to comment Share on other sites More sharing options...
trancexx Posted March 9, 2011 Share Posted March 9, 2011 pure io Would you be kind and make that picture in your signature smaller. ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
binarydigit0101 Posted March 9, 2011 Author Share Posted March 9, 2011 maybe that signature is too big... ehi ehi ehi, what is your name? Link to comment Share on other sites More sharing options...
Newb Posted March 9, 2011 Share Posted March 9, 2011 Would you be kind and make that picture in your signature smaller.Sure.Before, it was like 3 times bigger, i reduced it to make less bothering, and yet is too big lol. Gimme 5 minutes I'm a compulsive poster. When I post something, come to read it at least 5 minutes later after the posting, because I will edit it. I edited even this signature a few minutes later after I wrote it. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now