AlexFing17 Posted April 22, 2017 Share Posted April 22, 2017 hello, from help from this forum i have been able to create many programs, with credits to everyone who help. I am creating another app. But stucked. My app has a client and server which, the client connects the server and opens a chat box. PROBLEM. It connects to the server if ip and port are input in a pop-up box, before it connects. WHAT I NEED> instead of the pop up input box. I want the box to be in the gui. Whereby if i enter the ip and port and then click on connect, then i will connect. Below is pic of the pop-up and how i want it to be link in the gui.. And also the code is below expandcollapse popup#include <GUICONSTANTS.AU3> #include <WINDOWSCONSTANTS.AU3> #include <STATICCONSTANTS.AU3> #include <EDITCONSTANTS.AU3> #include <MISC.AU3> #Include <GuiEdit.au3> #Include <WinAPI.au3> #Include <DATE.au3> ; =============================================================================================================================== ; Global constants ; ========================================================================================================================== Opt ('GUIoneventmode', 1) $GUIStyle = BitOR($WS_DLGFRAME,$WS_POPUP, $WS_VISIBLE) $GUIStyleEx = BitOR ($WS_EX_TOPMOST,$WS_EX_WINDOWEDGE) $EditStyle = BitOR($ES_MULTILINE,$WS_VSCROLL) $EditStyleEx = BitOR($EditStyle, $ES_READONLY) $W = 0xFFFFFF $B = 0x0 $Titleb = 0x7F7F7F TCPStartup() $0 = 0 $00 = 0 $000 = 0 $ip = InputBox ('IP=?','Please choose a funtioning IP for your server...',@IPAddress1) ;Makes the servers IP address... default is your @IPADDRESS1. $port = InputBox ('Port=?','Please Choose a port # that is not being used...',Random (100, 10000,1)) ;Makes the port # can be anything between 1 and 60000. ;(the maximum is a guess i don't know how many ports there are butits close). ;and ONLY if the port is not already being used. ;MUST BE SERVER OPENED PORT NOT ONE ON YOUR COMPUTER!!! For $0 = 0 To 10 $Socket = TCPConnect($ip, $port) ;Connects to an open socket on the server... If $Socket <> -1 Then ExitLoop TCPCloseSocket($Socket) Sleep(300) Next If $Socket = -1 Then _Exit () TCPSend ($Socket, @UserName & '^EXAMPLE DATA') Local $GUI = GUICreate("FarC0nn3c7", 500, 400, -1, -1, $WS_SIZEBOX) Local $idHelpMenu = GUICtrlCreateMenu("Knowing you are better than what people say about you is a key to success--JIBRIL STURNA-----") GUICtrlCreateLabel("Server:", 2, 14, 52, 20, $SS_RIGHT) $ip = GUICtrlCreateEdit("127.0.0.1", 56, 10, 200, 20, $SS_LEFT) GUICtrlCreateLabel("Port:", 270, 14, 52, 20, $SS_Left) $port = GUICtrlCreateEdit("1000", 296, 10, 194, 20, $SS_LEFT) $g_idSend = GUICtrlCreateButton("Connect", 230, 32, 60, 20) GUISetBkColor(0x99CC00) $Console = GUICtrlCreateEdit ('',0,70,350,200,$EditStyleEx) $Send = GUICtrlCreateEdit ('Hello server',0,280,350,70,$EditStyle) GUICtrlSetLimit (-1, 250) GUISetOnEvent ($GUI_EVENT_CLOSE, '_Exit', $GUI) GUISetState () HotKeySet('{ENTER}', '_Send') While 1 _Recv_From_Server () Sleep(100) WEnd Func _Send () $0 = GUICtrlRead ($Send) If $0 = '' Then Return TCPSend($Socket, $0) GUICtrlSetData ($Send,'') EndFunc ;==>_send_ Func _Recv_From_Server () $Recv = TCPRecv($Socket, 1000000) If $Recv = '' Then Return _GUICtrlEdit_AppendText ($Console,_NowTime () & ' -- ' & $Recv & @CRLF) EndFunc ;==>_Recv_From_Server_ Func _Minn () WinSetState ($GUI, '', @SW_MINIMIZE) EndFunc Func _Exit () TCPCloseSocket ($Socket) TCPShutdown() Exit EndFunc ;==>_Exit_ Link to comment Share on other sites More sharing options...
InunoTaishou Posted April 22, 2017 Share Posted April 22, 2017 (edited) You could just make the button link to the _Connect function? expandcollapse popup#include <GUICONSTANTS.AU3> #include <WINDOWSCONSTANTS.AU3> #include <STATICCONSTANTS.AU3> #include <EDITCONSTANTS.AU3> #include <MISC.AU3> #include <GuiEdit.au3> #include <WinAPI.au3> #include <DATE.au3> ; =============================================================================================================================== ; Global constants ; ========================================================================================================================== Opt('GUIoneventmode', 1) $GUIStyle = BitOR($WS_DLGFRAME, $WS_POPUP, $WS_VISIBLE) $GUIStyleEx = BitOR($WS_EX_TOPMOST, $WS_EX_WINDOWEDGE) $EditStyle = BitOR($ES_MULTILINE, $WS_VSCROLL) $EditStyleEx = BitOR($EditStyle, $ES_READONLY) $W = 0xFFFFFF $B = 0x0 $Titleb = 0x7F7F7F TCPStartup() $0 = 0 $00 = 0 $000 = 0 Global $sIpAddress = "Default" Global $iPort = 1000 Global $Socket = -1 ;Makes the servers IP address... default is your @IPADDRESS1. ;Makes the port # can be anything between 1 and 60000. ;(the maximum is a guess i don't know how many ports there are butits close). ;and ONLY if the port is not already being used. ;MUST BE SERVER OPENED PORT NOT ONE ON YOUR COMPUTER!!! Global $GUI = GUICreate("FarC0nn3c7", 500, 400, -1, -1, $WS_SIZEBOX) Global $idHelpMenu = GUICtrlCreateMenu("Knowing you are better than what people say about you is a key to success--JIBRIL STURNA-----") Global $lblServer = GUICtrlCreateLabel("Server:", 2, 14, 52, 20, $SS_RIGHT) Global $inpIp = GUICtrlCreateInput($sIpAddress, 56, 10, 200, 20, $SS_LEFT) Global $lblPort = GUICtrlCreateLabel("Port:", 270, 14, 52, 20, $SS_Left) Global $inpPort = GUICtrlCreateInput($iPort, 296, 10, 194, 20, $SS_LEFT) Global $btnReconnect = GUICtrlCreateButton("Connect", 230, 32, 60, 20) Global $edtConsole = GUICtrlCreateEdit('', 0, 70, 350, 200, $EditStyleEx) Global $edtMsg = GUICtrlCreateEdit('Hello server', 0, 280, 350, 70, $EditStyle) GUICtrlSetLimit($edtMsg, 250) GUICtrlSetState($btnReconnect, $GUI_DISABLE) GUICtrlSetOnEvent($btnReconnect, _Connect) GUISetOnEvent($GUI_EVENT_CLOSE, '_Exit', $GUI) GUIRegisterMsg($WM_COMMAND, WM_COMMAND) GUISetState() HotKeySet('{ENTER}', '_Send') GUISetBkColor(0x99CC00) While 1 _Recv_From_Server() Sleep(100) WEnd Func _Connect() For $0 = 0 To 10 $Socket = TCPConnect($sIpAddress, $iPort) ;Connects to an open socket on the server... If $Socket <> -1 Then ExitLoop TCPCloseSocket($Socket) Sleep(300) Next If $Socket = -1 Then _Exit() TCPSend($Socket, @UserName & '^EXAMPLE DATA') GUICtrlSetData($btnReconnect, "Reconnect") EndFunc ;==>_Connect Func _Send() $0 = GUICtrlRead($edtMsg) If $0 = '' Then Return TCPSend($Socket, $0) GUICtrlSetData($edtMsg, '') EndFunc ;==>_Send Func _Recv_From_Server() $Recv = TCPRecv($Socket, 1000000) If $Recv = '' Then Return _GUICtrlEdit_AppendText($edtConsole, _NowTime() & ' -- ' & $Recv & @CRLF) EndFunc ;==>_Recv_From_Server Func _Minn() WinSetState($GUI, '', @SW_MINIMIZE) EndFunc ;==>_Minn Func _Exit() TCPCloseSocket($Socket) TCPShutdown() Exit EndFunc ;==>_Exit ; #FUNCTION# ==================================================================================================================== ; Name...........: _ValidIP ; Description ...: Verifies that an IP address is a valid IPv4 address or not ; Syntax.........: _ValidIP($sIP) ; Parameters ....: $sIP - IP address to validate ; ; Return values .: Success - True ; Failure - False, sets @error ; |1 - IP address starts with an invalid number = 0, 127 , 169 or is > 239 ; |2 - one of the octets of the IP address is out of the range 0-255 or contains invalid characters ; |3 - IP Address is not a valid dotted IP address (ex. valid address 190.40.100.20) ; Author ........: BrewManNH ; Modified.......: InunoTaishou: Return False instead of -1 on error and return True if valid IP address ; Remarks .......: Class A networks can't start with 0.xx.xx.xx. 127.xx.xx.xx isn't a valid IP address range. 169.xx.xx.xx is reserved and is invalid ; and any address that starts above 239, ex. 240.xx.xx.xx is reserved and should never be used or seen out in "the wild". ; The address range 224-239 1s reserved as well for Multicast groups but can be a valid IP address range if you're ; using it as such. ; This will validate an IP address that is 4 octets long, and contains only numbers and falls within valid IP address values. ; Anything else sent to it should fail the test and return -1. ; Related .......: ; Link ..........: _GetIP ; Example .......: No ; Topic .........: https://www.autoitscript.com/forum/topic/133593-ipv4-validator-function/ ; =============================================================================================================================== Func _ValidIP($sIP) $Array = StringSplit($sIP, ".", 2) If Not IsArray($Array) Or UBound($Array) <> 4 Then Return SetError(3, 0, False) $String = "0x" If $Array[0] <= 0 Or $Array[0] > 239 Or $Array[0] = 127 Or $Array[0] = 169 Then Return SetError(1, 0, False) EndIf For $I = 0 To 3 If $Array[$I] < 0 Or $Array[$I] > 255 Or Not StringIsDigit($Array[$I]) Then Return SetError(2, 0, False) EndIf Next Return True EndFunc ;==>_ValidIP Func _ValidPortNumber(Const $iPort) Return ($iPort >= 0 and $iPort <= 65535) EndFunc Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg Local Static $iTimer = Null Local $sReadValue = Null Local $iCtrlId = _WinAPI_LoWord($wParam) Switch (_WinAPI_HiWord($wParam)) Case $EN_CHANGE ; Sent when the user has taken an action that may have altered text in an edit/input control $sReadValue = GUICtrlRead($iCtrlId) Switch ($iCtrlId) Case $inpIp If (_ValidIP($sReadValue)) Then $sIpAddress = $sReadValue GUICtrlSetState($btnReconnect, $GUI_ENABLE) Else GUICtrlSetState($btnReconnect, $GUI_DISABLE) EndIf Case $inpPort If (_ValidPortNumber($sReadValue)) Then $iPort = Number($sReadValue) GUICtrlSetState($btnReconnect, $GUI_ENABLE) Else GUICtrlSetState($btnReconnect, $GUI_DISABLE) EndIf EndSwitch ; Could also auto connect right here if both the IP Address and Port are valid EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_COMMAND Edited May 4, 2017 by InunoTaishou AlexFing17 1 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