Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <MsgBoxConstants.au3>
- iniciarGUI()
- Func iniciarGUI()
- TCPStartup() ; Iniciamos servicio tcp
- OnAutoItExitRegister("OnAutoItExit")
- ;Asignamos una variable local que almacena la direccion de loopback
- Local $sIPAddress = "127.0.0.1"
- Local $iPort = 65432
- Local $accion = ""
- #include <ButtonConstants.au3>
- #include <GUIConstantsEx.au3>
- #include <WindowsConstants.au3>
- #Region ### START Koda GUI section ### Form=
- $Form1 = GUICreate("Networking - Cliente", 539, 433, 192, 132)
- $btnCalc = GUICtrlCreateButton("Calculadora", 96, 40, 369, 65)
- $btnBlock = GUICtrlCreateButton("Block de notas", 96, 136, 369, 65)
- $btnPaint = GUICtrlCreateButton("Paint", 96, 240, 369, 65)
- $btnSaludar = GUICtrlCreateButton("Saludar", 96, 336, 369, 65)
- GUISetState(@SW_SHOW)
- #EndRegion ### END Koda GUI section ###
- While 1
- $nMsg = GUIGetMsg()
- Switch $nMsg
- Case $GUI_EVENT_CLOSE
- Exit
- Case $btnCalc
- MyTCP_Client($sIPAddress, $iPort, "calculadora")
- Case $btnBlock
- MyTCP_Client($sIPAddress, $iPort, "blockNotas")
- Case $btnPaint
- MyTCP_Client($sIPAddress, $iPort, "paint")
- Case $btnSaludar
- MyTCP_Client($sIPAddress, $iPort, "saludar")
- EndSwitch
- WEnd
- EndFunc ; => Termina iniciarGUI()
- Func MyTCP_Client($sIPAddress, $iPort, $accion)
- Local $iSocket = TCPConnect($sIPAddress, $iPort)
- Local $iError = 0
- ;Chequeamos si podemos conectarnos a la ip y puerto definidos
- If @error Then
- msgbox(0, "Error", "Servidor apagado o puerto cerrado")
- return false
- EndIf
- ;Accion elegida por el cliente y luego enviada al servidor para ser procesada por el mismo
- switch $accion
- Case "calculadora"
- TCPSend($iSocket, "calculadora")
- Case "blockNotas"
- TCPSend($iSocket, "blockNotas")
- Case "paint"
- TCPSend($iSocket, "paint")
- Case "saludar"
- TCPSend($iSocket, "Hola como te va, espero que muy bien!!!!!!")
- EndSwitch
- ; Manejo de errores
- If @error Then
- $iError = @error
- MsgBox(0, "Error", "No se pudo enviar datos, codigo de error " & $iError)
- EndIf
- TCPCloseSocket($iSocket)
- EndFunc ; => MyTCP_Client
- Func OnAutoItExit()
- TCPShutdown();Cerrar el servicio tcp
- EndFunc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement