Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <MsgBoxConstants.au3>
- #include <Process.au3>
- iniciarGUI()
- Func iniciarGUI()
- ;inicializamos servicio tcp
- TCPStartup()
- ;si termina de ejecutarse el codigo que haga lo siguiente
- OnAutoItExitRegister("OnAutoItExit")
- Local $sIPAddress = "127.0.0.1"
- Local $iPort = 65432
- #include <ButtonConstants.au3>
- #include <EditConstants.au3>
- #include <GUIConstantsEx.au3>
- #include <StaticConstants.au3>
- #include <WindowsConstants.au3>
- #Region ### START Koda GUI section ### Form=
- $Form1 = GUICreate("Networking - Servidor", 613, 429, 192, 132)
- Global $txtMensajes = GUICtrlCreateEdit("", 40, 160, 513, 217)
- GUICtrlSetData(-1, "txtMensajes")
- $btnServidor = GUICtrlCreateButton("Iniciar Servidor", 40, 40, 225, 49)
- $Label1 = GUICtrlCreateLabel("Mensajes del cliente: ", 40, 120, 311, 40)
- GUICtrlSetFont(-1, 18, 800, 0, "MS Sans Serif")
- GUISetState(@SW_SHOW)
- #EndRegion ### END Koda GUI section ###
- While 1
- $nMsg = GUIGetMsg()
- Switch $nMsg
- Case $GUI_EVENT_CLOSE
- Exit
- Case $btnServidor
- GUICtrlSetState($btnServidor, $GUI_DISABLE)
- MyTCP_Server($sIPAddress, $iPort)
- EndSwitch
- WEnd
- EndFunc ; =>Termina iniciarGUI()
- Func MyTCP_Server($sIPAddress, $iPort)
- ;Nos ponemos a la escucha en la ip y puerto seleccionado con un maximo establecido de 100
- ;conecciones pendientes
- Local $iListenSocket = TCPListen($sIPAddress, $iPort, 100)
- Local $iError = 0
- If @error Then
- ;Alguien ya esta escuchando esa direccion ip y puerto o el script ya esta corriendo
- $iError = @error
- MsgBox(0, "Error", "Servidor no pudo escuchar, codigo de error: " & $iError)
- Return False
- EndIf
- ;Asignar una variable para ser usada por el socket del cliente
- Local $iSocket = 0
- Do
- ;Aceptamos conexiones entrantes, el socket cierra cuando termina, un socket por cliente
- $iSocket = TCPAccept($iListenSocket)
- if @error Then
- msgbox(0, "Error", "No se puede aceptar conecciones entrantes " & $iError)
- return False
- EndIf
- If GUIGetMsg() = $GUI_EVENT_CLOSE then return False
- Until $iSocket <> -1 ;si es diferente de -1 un cliente se pudo conectar
- TCPCloseSocket($iListenSocket)
- Local $sReceived = TCPRecv($iSocket, 2048)
- Switch $sReceived
- case "calculadora"
- _RunDos("start calc.exe")
- GUICtrlSetData($txtMensajes, "Abriendo Calculadora")
- case "blockNotas"
- _RunDos("start notepad.exe")
- GUICtrlSetData($txtMensajes, "Abriendo block de notas")
- case "paint"
- _RunDos("start mspaint.exe")
- GUICtrlSetData($txtMensajes, "Abriendo paint")
- case else
- GUICtrlSetData($txtMensajes, $sReceived)
- EndSwitch
- TCPCloseSocket($iSocket)
- MyTCP_Server($sIPAddress, $iPort)
- EndFunc ; => termina MyTCP_Server
- ;Cerramos el servicio TCP
- Func OnAutoItExit()
- TCPShutdown()
- EndFunc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement