Custom Query
Results (22 - 24 of 3883)
Ticket | Resolution | Summary | Owner | Reporter |
---|---|---|---|---|
#2669 | No Bug | TCP Send and TCP Receive (Example 2) | FireFox | AoRaToS |
Description |
Hello, There is an issue with the examples in these 2 functions. The server is also the one sending the file so there is a mistake. TCP Receive is the one that should be started first and wait for a connection. Then you run TCP Send and choose a file to send. Once TCP Receive sees the connection it asks where to save the file. The functions should be updated as below i believe. Tested and working. I have also updated the comments at the top to be correct. TCP Send: ; I am the client, start me after the server! (First start example 2 of the TCPRecv function). #include <MsgBoxConstants.au3> #include <FileConstants.au3> Example() Func Example() ; Assign a Local variable the path of a file chosen through a dialog box. Local $sFilePath = FileOpenDialog("Select a file to send", @MyDocumentsDir, "All types (*.*)", BitOR($FD_FILEMUSTEXIST, $FD_PATHMUSTEXIST)) Local $iError = 0 ; Note: Choose a file bigger than 4 kiB otherwise the first example is enough. ; If an error occurred display the error code and return False. If @error Then $iError = @error MsgBox(BitOR($MB_SYSTEMMODAL, $MB_ICONEXCLAMATION), "", "Server:" & @CRLF & "Invalid file chosen, Error code: " & $iError) Return False EndIf TCPStartup() ; Start the TCP service. ; Register OnAutoItExit to be called when the script is closed. OnAutoItExitRegister("OnAutoItExit") ; Assign Local variables the loopback IP Address and the Port. Local $sIPAddress = "127.0.0.1" ; This IP Address only works for testing on your own computer. Local $iPort = 65432 ; Port used for the connection. ; Assign a Local variable the socket and connect to a listening socket with the IP Address and Port specified. Local $iSocket = TCPConnect($sIPAddress, $iPort) Local $iError = 0 ; If an error occurred display the error code and return False. If @error Then ; The server is probably offline/port is not opened on the server. $iError = @error MsgBox(BitOR($MB_SYSTEMMODAL, $MB_ICONHAND), "", "Client:" & @CRLF & "Could not connect, Error code: " & $iError) Return False EndIf ; Assign a Local variable the size of the file previously chosen. Local $iFileSize = FileGetSize($sFilePath) ; Assign a Local variable the handle of the file opened in binary mode. Local $hFile = FileOpen($sFilePath, $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($iSocket, 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($iSocket) 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 client the file is fully sent with a code. TCPSend($iSocket, @CRLF & "{EOF}") ; Display the successful message. MsgBox($MB_SYSTEMMODAL, "", "Server:" & @CRLF & "File sent.") ; Close the socket. TCPCloseSocket($iSocket) EndFunc ;==>Example Func OnAutoItExit() TCPShutdown() ; Close the TCP service. EndFunc ;==>OnAutoItExit TCP Receive: ; I am the server, start me first! (The start example 2 of the TCPSend function). #include <MsgBoxConstants.au3> #include <FileConstants.au3> Example() Func Example() TCPStartup() ; Start the TCP service. ; Register OnAutoItExit to be called when the script is closed. OnAutoItExitRegister("OnAutoItExit") ; Assign Local variables the loopback IP Address and the Port. Local $sIPAddress = "127.0.0.1" ; This IP Address only works for testing on your own computer. Local $iPort = 65432 ; Port used for the connection. ; Assign a Local variable the socket and bind to the IP Address and Port specified with a maximum of 100 pending connexions. Local $iListenSocket = TCPListen($sIPAddress, $iPort, 100) ; If an error occurred display the error code and return False. If @error Then ; Someone is probably already listening on this IP Address and Port (script already running?). $iError = @error MsgBox(BitOR($MB_SYSTEMMODAL, $MB_ICONHAND), "", "Server:" & @CRLF & "Could not listen, Error code: " & $iError) Return False EndIf ; Assign a Local variable to be used by the Client socket. Local $iSocket = 0 Do ; Wait for someone to connect (Unlimited). ; Accept incomming connexions if present (Socket to close when finished; one socket per client). $iSocket = TCPAccept($iListenSocket) ; 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 accept the incoming connection, Error code: " & $iError) Return False EndIf Until $iSocket <> -1 ;if different from -1 a client is connected. ; Close the Listening socket to allow afterward binds. TCPCloseSocket($iListenSocket) ; Assign a Local variable the path of the file which will be received. Local $sFilePath = FileSaveDialog("Save as", @MyDocumentsDir, "All types (*.*)", BitOR($FD_PATHMUSTEXIST, $FD_PROMPTOVERWRITE)) ; If an error occurred display the error code and return False. If @error Then $iError = @error MsgBox(BitOR($MB_SYSTEMMODAL, $MB_ICONEXCLAMATION), "", "Client:" & @CRLF & "Invalid file chosen, Error code: " & $iError) Return False EndIf ; Assign a Local variable the handle of the file opened in binary overwrite mode. Local $hFile = FileOpen($sFilePath, 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 $bData = TCPRecv($iSocket, $i4KiB, 1) ; 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.") ; Close the socket. TCPCloseSocket($iSocket) EndFunc ;==>Example Func OnAutoItExit() TCPShutdown() ; Close the TCP service. EndFunc ;==>OnAutoItExit |
|||
#7 | Fixed | Example for _GUICtrlListView_AddArray uses _GUICtrlListView_DeleteAllItems in Example_Internal() | Gary | Saunders |
Description |
Since the _GUICtrlListView_DeleteAllItems has been modified to not work with built-in listviews and listview items, the first example does not work properly, displaying an error MsgBox() with the notification to use GUICtrlDelete. |
|||
#9 | Fixed | _GUICtrlRebar_AddToolBarBand(): Button height clipped when Toolbar added to Rebar | Gary | rover |
Description |
Reversed _WinAPI_LoWord and _WinAPI_HiWord for setting rebar height in function _GUICtrlRebar_AddToolBarBand() in include GuiReBar.au3 Reproducer script ; version 3.2.9.10 and 3.2.9.14 #include <GuiConstantsEx.au3> #include <GuiToolbar.au3> #include <GuiReBar.au3> #Include <GuiImageList.au3> Opt('MustDeclareVars', 1) _Main() Func _Main() Local $hGUI, $hToolbar, $hReBar, $btn1, $btn2, $aStrings[4], $msg Local Enum $idNew = 1000, $idOpen, $idSave, $idHelp $hGUI = GUICreate("Toolbar", 400, 200) $hReBar = _GUICtrlReBar_Create($hgui, BitOR($RBS_VARHEIGHT, $RBS_AUTOSIZE, $RBS_BANDBORDERS)) $hToolbar = _GUICtrlToolbar_Create ($hGUI, BitOR($TBSTYLE_FLAT, $CCS_NORESIZE, $CCS_NOPARENTALIGN)) _GUICtrlToolbar_SetButtonWidth($hToolbar, 32, 40) ; limit button width (force text to word wrap to second row) _GUICtrlToolbar_SetMaxTextRows($hToolbar, 2) ; allow two rows of text _GUICtrlToolbar_AddBitmap ($hToolbar, 1, -1, $IDB_STD_LARGE_COLOR) $aStrings[0] = _GUICtrlToolbar_AddString ($hToolbar, "&New File") $aStrings[1] = _GUICtrlToolbar_AddString ($hToolbar, "&Open File") $aStrings[2] = _GUICtrlToolbar_AddString ($hToolbar, "&Save File") $aStrings[3] = _GUICtrlToolbar_AddString ($hToolbar, "&Help") _GUICtrlToolbar_AddButton ($hToolbar, $idNew, $STD_FILENEW, $aStrings[0]) _GUICtrlToolbar_AddButton ($hToolbar, $idOpen, $STD_FILEOPEN, $aStrings[1]) _GUICtrlToolbar_AddButton ($hToolbar, $idSave, $STD_FILESAVE, $aStrings[2]) _GUICtrlToolbar_AddButtonSep ($hToolbar) _GUICtrlToolbar_AddButton ($hToolbar, $idHelp, $STD_HELP, $aStrings[3]) $btn1 = GUICtrlCreateButton("Add ToolBarBand Fixed",50, 100, 150,25) $btn2 = GUICtrlCreateButton("Add ToolBarBand v3.2.9.14",50, 150, 150,25) ;_GUICtrlToolbar_SetButtonSize($hToolbar, 60, 40) GUISetState() Do $msg = GUIGetMsg() Switch $msg Case $btn1 ; AddToolBarBand with fix _GUICtrlRebar_DeleteBand($hReBar, 0) _MOD_GUICtrlReBar_AddToolBarBand($hReBar, $hToolbar, "", 0) Case $btn2 ; AddToolBarBand v3.2.9.14 _GUICtrlRebar_DeleteBand($hReBar, 0) _GUICtrlReBar_AddToolBarBand($hReBar, $hToolbar, "", 0) EndSwitch Until $msg = $GUI_EVENT_CLOSE EndFunc ;==>_Main Func _MOD_GUICtrlRebar_AddToolBarBand($hwndRebar, $hwndToolbar, $sText = "", $iIndex = -1, $fStyle = -1) If $Debug_RB Then _GUICtrlRebar_ValidateClassName($hwndRebar) If $Debug_RB Then _GUICtrlRebar_ValidateClassName($hwndToolbar, "ToolbarWindow32") Local $tBuffer, $pBuffer, $dwBtnSize, $NumButtons, $iDefaultWidth Local $pMemory, $tMemMap, $pText, $iResult Local $tINFO = DllStructCreate($tagREBARBANDINFO) Local $pINFO = DllStructGetPtr($tINFO) Local $iBuffer = StringLen($sText) + 1 Local $iSize = DllStructGetSize($tINFO) If $fStyle <> -1 Then $fStyle = BitOR($fStyle, $RBBS_CHILDEDGE, $RBBS_GRIPPERALWAYS) Else $fStyle = BitOR($RBBS_CHILDEDGE, $RBBS_GRIPPERALWAYS) EndIf ;// Initialize band info used by the toolbar DllStructSetData($tINFO, "cbSize", $iSize) DllStructSetData($tINFO, "fMask", BitOR($RBBIM_STYLE, $RBBIM_TEXT, $RBBIM_CHILD, $RBBIM_CHILDSIZE, $RBBIM_SIZE, $RBBIM_ID)) DllStructSetData($tINFO, "fStyle", $fStyle) ;// Get the height of the toolbar. $dwBtnSize = _SendMessage($hwndToolbar, $TB_GETBUTTONSIZE) ; Get the number of buttons contained in toolbar for calculation $NumButtons = _SendMessage($hwndToolbar, $TB_BUTTONCOUNT) $iDefaultWidth = $NumButtons * _WinAPI_LoWord($dwBtnSize) ; was _WinAPI_HiWord($dwBtnSize) ;// Set values unique to the band with the toolbar. $tBuffer = DllStructCreate("char Text[" & $iBuffer & "]") DllStructSetData($tBuffer, "Text", $sText) $pBuffer = DllStructGetPtr($tBuffer) DllStructSetData($tINFO, "hwndChild", $hwndToolbar) DllStructSetData($tINFO, "cyChild", _WinAPI_HiWord($dwBtnSize)) ; was _WinAPI_LoWord($dwBtnSize) DllStructSetData($tINFO, "cxMinChild", $iDefaultWidth) DllStructSetData($tINFO, "cyMinChild", _WinAPI_HiWord($dwBtnSize)) ; was _WinAPI_LoWord($dwBtnSize) DllStructSetData($tINFO, "cx", $iDefaultWidth) ;// The default width is the width of the buttons. DllStructSetData($tINFO, "wID", _GUICtrlRebar_GetBandCount($hwndRebar)) ;// Add the band that has the toolbar. $pMemory = _MemInit($hwndRebar, $iSize + $iBuffer, $tMemMap) $pText = $pMemory + $iSize DllStructSetData($tINFO, "lpText", $pText) _MemWrite($tMemMap, $pINFO, $pMemory, $iSize) _MemWrite($tMemMap, $pBuffer, $pText, $iBuffer) ;// Add the band that has the combobox If _GUICtrlRebar_GetUnicodeFormat($hwndRebar) Then $iResult = _SendMessage($hwndRebar, $RB_INSERTBANDW, $iIndex, $pMemory, 0, "int", "ptr") <> 0 Else $iResult = _SendMessage($hwndRebar, $RB_INSERTBANDA, $iIndex, $pMemory, 0, "int", "ptr") <> 0 EndIf _MemFree($tMemMap) Return $iResult EndFunc ;==>_GUICtrlRebar_AddToolBarBand |