Advertisement
Guest User

Código del cliente

a guest
Oct 27th, 2018
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 2.15 KB | None | 0 0
  1. #include <MsgBoxConstants.au3>
  2.  
  3. iniciarGUI()
  4.  
  5. Func iniciarGUI()
  6.  
  7. TCPStartup() ; Iniciamos servicio tcp
  8.  
  9. OnAutoItExitRegister("OnAutoItExit")
  10.  
  11. ;Asignamos una variable local que almacena la direccion de loopback
  12.  
  13. Local $sIPAddress = "127.0.0.1"
  14. Local $iPort      = 65432
  15.  
  16. Local $accion = ""
  17.  
  18.  
  19. #include <ButtonConstants.au3>
  20. #include <GUIConstantsEx.au3>
  21. #include <WindowsConstants.au3>
  22.  
  23. #Region ### START Koda GUI section ### Form=
  24. $Form1 = GUICreate("Networking - Cliente", 539, 433, 192, 132)
  25. $btnCalc = GUICtrlCreateButton("Calculadora", 96, 40, 369, 65)
  26. $btnBlock = GUICtrlCreateButton("Block de notas", 96, 136, 369, 65)
  27. $btnPaint = GUICtrlCreateButton("Paint", 96, 240, 369, 65)
  28. $btnSaludar = GUICtrlCreateButton("Saludar", 96, 336, 369, 65)
  29. GUISetState(@SW_SHOW)
  30. #EndRegion ### END Koda GUI section ###
  31.  
  32. While 1
  33.     $nMsg = GUIGetMsg()
  34.     Switch $nMsg
  35.         Case $GUI_EVENT_CLOSE
  36.             Exit
  37.         Case $btnCalc
  38.             MyTCP_Client($sIPAddress, $iPort, "calculadora")
  39.         Case $btnBlock
  40.             MyTCP_Client($sIPAddress, $iPort, "blockNotas")
  41.         Case $btnPaint
  42.             MyTCP_Client($sIPAddress, $iPort, "paint")
  43.         Case $btnSaludar
  44.             MyTCP_Client($sIPAddress, $iPort, "saludar")
  45.  
  46.     EndSwitch
  47. WEnd
  48. EndFunc ; => Termina iniciarGUI()
  49.  
  50.  
  51. Func MyTCP_Client($sIPAddress, $iPort, $accion)
  52.     Local $iSocket = TCPConnect($sIPAddress, $iPort)
  53.     Local $iError = 0
  54.  
  55.     ;Chequeamos si podemos conectarnos a la ip y puerto definidos
  56.     If @error Then
  57.         msgbox(0, "Error", "Servidor apagado o puerto cerrado")
  58.         return false
  59.     EndIf
  60.  
  61.     ;Accion elegida por el cliente y luego enviada al servidor para ser procesada por el mismo
  62.     switch $accion
  63.         Case "calculadora"
  64.             TCPSend($iSocket, "calculadora")
  65.         Case "blockNotas"
  66.             TCPSend($iSocket, "blockNotas")
  67.         Case "paint"
  68.             TCPSend($iSocket, "paint")
  69.         Case "saludar"
  70.             TCPSend($iSocket, "Hola como te va, espero que muy bien!!!!!!")
  71.     EndSwitch
  72.  
  73.  
  74.     ; Manejo de errores
  75.  
  76.     If @error Then
  77.         $iError = @error
  78.         MsgBox(0, "Error", "No se pudo enviar datos, codigo de error " & $iError)
  79.     EndIf
  80.  
  81.     TCPCloseSocket($iSocket)
  82.  
  83. EndFunc ; => MyTCP_Client
  84.  
  85.  
  86. Func OnAutoItExit()
  87.     TCPShutdown();Cerrar el servicio tcp
  88.  
  89. EndFunc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement