Jump to content

binarydigit0101

Active Members
  • Posts

    75
  • Joined

  • Last visited

Everything posted by binarydigit0101

  1. it is surely an issue. you are so good to makin' cleary examples. thank you, then.
  2. I don't have any project atm... I like to create a new one if this is possible. when you manage a server running under a console, you can read what server says and at the same time writing for new commands. how can make D.O.S. inputoutput with autoit? you can notice this especially in-game consoles.
  3. oh... I am sorry. Thank you!
  4. where am I wrong?
  5. ; THIS IS THE SERVER #include <File.au3> TCPStartup() $listen = TCPListen("127.0.0.1", 5555) While 1 $socket = TCPAccept($listen) If $socket <> -1 Then example() EndIf WEnd Func example() $yourfile = "COMPLETE PATH FOR THE FILE" $pause = 0 $result = TCPSend($socket, "data") ConsoleWrite("it is the hell!") Do $canContinue = TCPRecv($socket, 100) Until $canContinue <> "" ;~ Sleep($pause) $result = TCPSend($socket, "data") ConsoleWrite("it is the hell!") Do $canContinue = TCPRecv($socket, 100) Until $canContinue <> "" ;~ Sleep($pause) #region Br, FireFox ;~ ; Assign a Local variable the size of the file previously chosen. Local $iFileSize = FileGetSize($yourfile) ; Assign a Local variable the handle of the file opened in binary mode. Local $hFile = FileOpen($yourfile, $FO_BINARY) ; Assign a Local variable the offset of the file being read. Local $iOffset = 0 ; Assign a Local variable the number representing 4 KiB. Local Const $i4KiB = 4096 ; Note: The file is send by parts of 4 KiB. ; Send the binary data of the file to the server. Do ; Set the file position to the current offset. FileSetPos($hFile, $iOffset, $FILE_BEGIN) ; The file is read from the position set to 4 KiB and directly wrapped into the TCPSend function. TCPSend($Socket, FileRead($hFile, $i4KiB)) ; If an error occurred display the error code and return False. If @error Then $iError = @error MsgBox(BitOR($MB_SYSTEMMODAL, $MB_ICONHAND), "", "Server:" & @CRLF & "Could not send the data, Error code: " & $iError) ; Close the socket. TCPCloseSocket($Socket) Return False EndIf ; Increment the offset of 4 KiB to send the next 4 KiB data. $iOffset += $i4KiB Until $iOffset >= $iFileSize ; Close the file handle. FileClose($hFile) ; Tell the server the file is fully sent with a code. TCPSend($Socket, @CRLF & "{EOF}") ; Display the successful message. ; MsgBox($MB_SYSTEMMODAL, "", "Server:" & @CRLF & "File sent.") #endregion Br, FireFox Do $canContinue = TCPRecv($socket, 100) Until $canContinue <> "" ;~ Sleep($pause) $result = TCPSend($socket, "data") ConsoleWrite("it is the hell!") Do $canContinue = TCPRecv($socket, 100) Until $canContinue <> "" ;~ Sleep($pause) $result = TCPSend($socket, "data") ConsoleWrite("it is the hell!") Do $canContinue = TCPRecv($socket, 100) Until $canContinue <> "" ;~ Sleep($pause) $result = TCPSend($socket, "data") ConsoleWrite("it is the hell!") ;~ Sleep($pause) EndFunc ; THIS IS THE CLIENT #include <File.au3> TCPStartup() $socket = TCPConnect("127.0.0.1", 5555) $yourfile = "COMPLETE PATH FOR THE FILE" Do $var1 = TCPRecv($socket, 100) Until $var1 <> "" ConsoleWrite("var1 received" & @CRLF) TCPSend($socket, "ok") Do $var2 = TCPRecv($socket, 100) Until $var2 <> "" ConsoleWrite("var2 received" & @CRLF) TCPSend($socket, "ok") #region Br, FireFox ; Assign a Local variable the handle of the file opened in binary overwrite mode. Local $hFile = FileOpen($yourfile, BitOR($FO_BINARY, $FO_OVERWRITE)) ; Assign Locales Constant variables the number representing 4 KiB; the binary code for the end of the file and the length of the binary code. Local Const $i4KiB = 4096, $bEOF = Binary(@CRLF & "{EOF}"), $iEOFLen = BinaryLen($bEOF) ; Assign a Local variable the empty binary data which will contain the binary data of the file. Local $bData = Binary("") ; Assign a Local variable to store the length of the data received. Local $iDataLen = 0 ; Assign a Local variable a boolean. Local $fEOFReached = False Do Do $bData = TCPRecv($Socket, $i4KiB, 1) Until $bData <> "" ; If an error occurred display the error code and return False. If @error Then $iError = @error MsgBox(BitOR($MB_SYSTEMMODAL, $MB_ICONHAND), "", "Client:" & @CRLF & "Connection lost, Error code: " & $iError) Return False EndIf $iDataLen = BinaryLen($bData) ; If nothing is received, retry for the incoming data. If $iDataLen = 0 Then ContinueLoop ; If the end of the file is reached. If BinaryMid($bData, 1 + $iDataLen - $iEOFLen, $iEOFLen) = $bEOF Then ; Strip the EOF code from the file data. $bData = BinaryMid($bData, 1, $iDataLen - $iEOFLen) ; Set the EOFReached to True. $fEOFReached = True EndIf FileWrite($hFile, $bData) Until $fEOFReached ; Close the file handle. FileClose($hFile) ; Display the successful message. ; MsgBox($MB_SYSTEMMODAL, "", "Client:" & @CRLF & "File received.") #endregion Br, FireFox TCPSend($socket, "ok") Do $var3 = TCPRecv($socket, 100) Until $var3 <> "" ConsoleWrite("var3 received" & @CRLF) TCPSend($socket, "ok") Do $var4 = TCPRecv($socket, 100) Until $var4 <> "" ConsoleWrite("var4 received" & @CRLF) TCPSend($socket, "ok") Do $var5 = TCPRecv($socket, 100) Until $var5 <> "" ConsoleWrite("var5 received" & @CRLF) like the server, as such the client. when the client receive a new string, it confirms back it receives it: in this way the client waits for server and viceversa. if one of two block itself, both block themselves. I don't understand what you mean and how I can send files using EOF. P.S.: is it necessary to close a socket when the program ends? is it necessary also shutdown tcp when programs end? because sometimes it runs good, sometimes not. I don't know if it is a bad code I wrote or it is just I miss to initialize another tcp session. thank you
  6. what do you mean? do you mean I need a screen session to control using autoit? or do I just note server messages while administrator can send commands?
  7. ok, I presume it isn't possible. thank you all
  8. did I make a stupid error?
  9. perfect!! i tried to reproduce what happens to me and i succeed! what you have to do is to set-up $yourfile(s) vars with parameters you choose and leave $pause at 0. running the program let you see the server continues to send messages without wait for client receives them. client will block at your image receiving code which will create the file, keeping it blocked. when you kill the client, the file is released so it is received (problem solved) but other data after the file are missed. the server anyway is ready to receive another connection from the client and same events will happen. i tried to make it working, simply changing time of $pause: it waits for a time after every send to the client - - i tried it with 5 seconds and seems to work fine but i guess it is so long for a server application. where am i wrong? how can i fix it? ; THIS IS THE SERVER #include <File.au3> TCPStartup() $listen = TCPListen("127.0.0.1", 5555) While 1 $socket = TCPAccept($listen) If $socket <> -1 Then example() EndIf WEnd Func example() $yourfile = "COMPLETE PATH OF FILE TO SEND" $pause = 0 $result = TCPSend($socket, "data") ConsoleWrite("it is the hell!") Sleep($pause) $result = TCPSend($socket, "data") ConsoleWrite("it is the hell!") Sleep($pause) ;~ ; Assign a Local variable the size of the file previously chosen. Local $iFileSize = FileGetSize($yourfile) ; Assign a Local variable the handle of the file opened in binary mode. Local $hFile = FileOpen($yourfile, $FO_BINARY) ; Assign a Local variable the offset of the file being read. Local $iOffset = 0 ; Assign a Local variable the number representing 4 KiB. Local Const $i4KiB = 4096 ; Note: The file is send by parts of 4 KiB. ; Send the binary data of the file to the server. Do ; Set the file position to the current offset. FileSetPos($hFile, $iOffset, $FILE_BEGIN) ; The file is read from the position set to 4 KiB and directly wrapped into the TCPSend function. TCPSend($Socket, FileRead($hFile, $i4KiB)) ; If an error occurred display the error code and return False. If @error Then $iError = @error MsgBox(BitOR($MB_SYSTEMMODAL, $MB_ICONHAND), "", "Server:" & @CRLF & "Could not send the data, Error code: " & $iError) ; Close the socket. TCPCloseSocket($Socket) Return False EndIf ; Increment the offset of 4 KiB to send the next 4 KiB data. $iOffset += $i4KiB Until $iOffset >= $iFileSize ; Close the file handle. FileClose($hFile) ; Tell the server the file is fully sent with a code. TCPSend($Socket, @CRLF & "{EOF}") ; Display the successful message. ; MsgBox($MB_SYSTEMMODAL, "", "Server:" & @CRLF & "File sent.") Sleep($pause) $result = TCPSend($socket, "data") ConsoleWrite("it is the hell!") Sleep($pause) $result = TCPSend($socket, "data") ConsoleWrite("it is the hell!") Sleep($pause) $result = TCPSend($socket, "data") ConsoleWrite("it is the hell!") Sleep($pause) EndFunc ; THIS IS THE CLIENT #include <File.au3> TCPStartup() $socket = TCPConnect("127.0.0.1", 5555) $yourfile = "COMPLETE PATH OF FILE TO RECEIVE" Do $var1 = TCPRecv($socket, 100) Until $var1 <> "" ConsoleWrite("received" & @CRLF) Do $var2 = TCPRecv($socket, 100) Until $var2 <> "" ConsoleWrite("received" & @CRLF) ; Assign a Local variable the handle of the file opened in binary overwrite mode. Local $hFile = FileOpen($yourfile, BitOR($FO_BINARY, $FO_OVERWRITE)) ; Assign Locales Constant variables the number representing 4 KiB; the binary code for the end of the file and the length of the binary code. Local Const $i4KiB = 4096, $bEOF = Binary(@CRLF & "{EOF}"), $iEOFLen = BinaryLen($bEOF) ; Assign a Local variable the empty binary data which will contain the binary data of the file. Local $bData = Binary("") ; Assign a Local variable to store the length of the data received. Local $iDataLen = 0 ; Assign a Local variable a boolean. Local $fEOFReached = False Do Do $bData = TCPRecv($Socket, $i4KiB, 1) Until $bData <> "" ; If an error occurred display the error code and return False. If @error Then $iError = @error MsgBox(BitOR($MB_SYSTEMMODAL, $MB_ICONHAND), "", "Client:" & @CRLF & "Connection lost, Error code: " & $iError) Return False EndIf $iDataLen = BinaryLen($bData) ; If nothing is received, retry for the incoming data. If $iDataLen = 0 Then ContinueLoop ; If the end of the file is reached. If BinaryMid($bData, 1 + $iDataLen - $iEOFLen, $iEOFLen) = $bEOF Then ; Strip the EOF code from the file data. $bData = BinaryMid($bData, 1, $iDataLen - $iEOFLen) ; Set the EOFReached to True. $fEOFReached = True EndIf FileWrite($hFile, $bData) Until $fEOFReached ; Close the file handle. FileClose($hFile) ; Display the successful message. ; MsgBox($MB_SYSTEMMODAL, "", "Client:" & @CRLF & "File received.") Do $var3 = TCPRecv($socket, 100) Until $var3 <> "" ConsoleWrite("received" & @CRLF) Do $var4 = TCPRecv($socket, 100) Until $var4 <> "" ConsoleWrite("received" & @CRLF) Do $var5 = TCPRecv($socket, 100) Until $var5 <> "" ConsoleWrite("received" & @CRLF) thank you
  10. good, my copy-abilities are really good, I saw! I only had to copy!! lol - sorry man, I'm so sorry. now, the code itself works great. what don't work are TCP functions (send and receive) before and next the code: I guess this operation take a few time. may I slow it down inserting some sleeps before and next the transfer? because I tested it without any pause and it continues to block again. if you need code, please tell me. thank you
  11. personally I find your way good, because all the computers refer to the same server. when a certain event is met, computers that need the file will connect to the server or to the cloud if you want to manage more servers and check for the file they missed. currently i am trying to understand how to send files over TCP which like you said it doesn't seem so easy. if exist other methods it would be cool because they'd make all more simple. see ya!
  12. #include <File.au3> $path = INSERT THE PATH FOR THE FILE TCPStartup() $ascolto = TCPListen("127.0.0.1", 5555) While 1 $socket = TCPAccept($ascolto) If $socket <> -1 Then ; Assign a Local variable the size of the file previously chosen. Local $iFileSize = FileGetSize($percorso) ; Assign a Local variable the handle of the file opened in binary mode. Local $hFile = FileOpen($percorso, $FO_BINARY) ; Assign a Local variable the offset of the file being read. Local $iOffset = 0 ; Assign a Local variable the number representing 4 KiB. Local Const $i4KiB = 4096 ; Note: The file is send by parts of 4 KiB. ; Send the binary data of the file to the server. Do ; Set the file position to the current offset. FileSetPos($hFile, $iOffset, $FILE_BEGIN) ; The file is read from the position set to 4 KiB and directly wrapped into the TCPSend function. TCPSend($Socket, FileRead($hFile, $i4KiB)) ; If an error occurred display the error code and return False. If @error Then $iError = @error MsgBox(BitOR($MB_SYSTEMMODAL, $MB_ICONHAND), "", "Server:" & @CRLF & "Could not send the data, Error code: " & $iError) ; Close the socket. TCPCloseSocket($Socket) Return False EndIf ; Increment the offset of 4 KiB to send the next 4 KiB data. $iOffset += $i4KiB Until $iOffset >= $iFileSize ; Close the file handle. FileClose($hFile) ConsoleWrite("ok") EndIf WEnd #include <File.au3> $file = WHERE TO SAVE THE FILE TCPStartup() $socket = TCPConnect("127.0.0.1", 5555) ; Assign a Local variable the handle of the file opened in binary overwrite mode. Local $hFile = FileOpen($file, BitOR($FO_BINARY, $FO_OVERWRITE)) ; Assign Locales Constant variables the number representing 4 KiB; the binary code for the end of the file and the length of the binary code. Local Const $i4KiB = 4096, $bEOF = Binary(@CRLF & "{EOF}"), $iEOFLen = BinaryLen($bEOF) ; Assign a Local variable the empty binary data which will contain the binary data of the file. Local $bData = Binary("") ; Assign a Local variable to store the length of the data received. Local $iDataLen = 0 ; Assign a Local variable a boolean. Local $fEOFReached = False Do Do $bData = TCPRecv($Socket, $i4KiB, 1) Until $bData <> "" ; If an error occurred display the error code and return False. If @error Then $iError = @error MsgBox(BitOR($MB_SYSTEMMODAL, $MB_ICONHAND), "", "Client:" & @CRLF & "Connection lost, Error code: " & $iError) Return False EndIf $iDataLen = BinaryLen($bData) ; If nothing is received, retry for the incoming data. If $iDataLen = 0 Then ContinueLoop ; If the end of the file is reached. If BinaryMid($bData, 1 + $iDataLen - $iEOFLen, $iEOFLen) = $bEOF Then ; Strip the EOF code from the file data. $bData = BinaryMid($bData, 1, $iDataLen - $iEOFLen) ; Set the EOFReached to True. $fEOFReached = True EndIf FileWrite($hFile, $bData) Until $fEOFReached ; Close the file handle. FileClose($hFile) ; Display the successful message. MsgBox($MB_SYSTEMMODAL, "", "Client:" & @CRLF & "File received.") above there is the server, under there is the client. insert your paths and check at runtime - here, it receives the file but the file is blocked until the client is stopped. why?
  13. so, I didn't tried with a progress GUI. I'm just transferring files without any control. when the server executes send instruction, it seems everything worked fine and server continues to run, but the client blocks itself somewhere: it creates the file but it seems it can't close it: indeed, when you terminate the client, the file is unblocked and complete. I guess I copied the example on the manual but I don't know how to check where script blocks because every cycle it receives a piece of file and this should generate many check messages. update: it seems like the end of the file isn't reached.
  14. alright, please help me to get in the case: it seems it blocks many times: it works a few and then the script holds the image without continuing. when you stop it, the image completes because i guess it was blocked from the script. how do i need to do for avoiding this kind of event? does it need a script pause before its continuation? thank you, firefox
  15. woooa!!! is there only for beta? what is that: ; Assign a Local variable the number representing 4 KiB. Local Const $i4KiB = 4096 thank you
  16. hello coders!! I found a few examples about file transfer over the internet but I can't make them work. Do you have a working example? I don't need any GUI or complex functions. I just send images and executable files from server to client or viceversa. thank you for your help!
  17. I succeeded to create a client-server program. now I need to make it more powerful adding to the server a function I would know if it is possible being autoit single-thread. do you know if this can be implemented? thank you again,
  18. I can't understand what ConsoleRead does, but you can write using ConsoleWrite. About interpreting commands, I found this great function from ResNullius (here - ): ;credits to Valik & Mat #AutoIt3Wrapper_Change2CUI=y #include <WinAPI.au3> $sResponse = _ConsoleInput("Please input some text: ") ConsoleWrite("You Entered: " & $sResponse & @CRLF) Func _ConsoleInput($sPrompt) If Not @Compiled Then Return SetError(1, 0, 0) ; Not compiled ConsoleWrite($sPrompt) Local $tBuffer = DllStructCreate("char"), $nRead, $sRet = "" Local $hFile = _WinAPI_CreateFile("CON", 2, 2) While 1 _WinAPI_ReadFile($hFile, DllStructGetPtr($tBuffer), 1, $nRead) If DllStructGetData($tBuffer, 1) = @CR Then ExitLoop If $nRead > 0 Then $sRet &= DllStructGetData($tBuffer, 1) WEnd _WinAPI_CloseHandle($hFile) Return $sRet EndFunc
  19. hey there! I am still here! now, always knowing autoit isn't multi-threads, I need if it is possible to create a server application which permits the administrator to read what it's happening on the server, and send commands to it at the same time. I think it isn't so easy but I would know if it's possible. actually I'm using a console script, I appreciate a support about a GUI as well. thank you so much for your answers!
  20. so, probably I understood. please wait. I'll try to search a bug into my code so multi clients will work also for me. alright!!! I checked it and I find what was wrong: you are right when you say it accepts many connections but it will manage them one by one. I mean: when a client will connect I think it is put into an array but when it sends or receives message, it needs to be the only served from the server, so you need to create a three way handshake: client request (tcpconnect), server answer (tcpsend) and flush start of client (tcprecv for answer and others for communication). thank you so much hear you soon
  21. exactly! if the code is looping through clients (3rd point), how can it accept new connection (1st and 2nd points)? because I guess it is still busy!
  22. I guess here the listening socket accepts a new connection and inserts it into the array: ; If a new client is connected. If $iSocket <> -1 Then For $i = 0 To $_iMaxClients - 1 If($_aClient[$i][$_iClientSubIdx_Socket] <> "") Then ContinueLoop GUICtrlCreateListViewItem(SocketToIP($iSocket) & "|" & _Now(), $_iLwClient) $_aClient[$i][$_iClientSubIdx_Item] = _GUICtrlListView_GetItemCount($_hLwClient) - 1 $_aClient[$i][$_iClientSubIdx_Socket] = $iSocket ExitLoop Next EndIf next it loops through connected clients it finds in the array: ; Loop through the connected clients. For $i = 0 To $_iMaxClients - 1 If($_aClient[$i][$_iClientSubIdx_Socket] = "") Then ContinueLoop ; Receive from the client a maximum of 4 KiB data. $vRecv = TCPRecv($_aClient[$i][$_iClientSubIdx_Socket], 4096) ; If an error occurred disconnect the client and process the next one. If @error Then _Client_Disconnect($i) ContinueLoop EndIf now, I can't understand how can the code add a new user to array if it is processing the last loop.
  23. thank you for your complex code, I thought you made a simple one . it is quite hard for me to understand all its features, because I am a beginner. by the way I can't still understand what permits you to process an action while you're listening to other client connections. is it the array or a background function?
×
×
  • Create New...