我在一家旅行社工作,我们一直在使用Autoit。我们有一个使用Autoit制作的工作TCP服务器但我们的客户端不起作用。
这是错误的代码
$port = 1942
$addr = 192.168.101.111
$connexion = TCPConnect($addr, $port)
TCPSend("bus has arrived")
TCPCloseSocket($connexion)
答案 0 :(得分:1)
欢迎使用StackOverflow。发布问题时,您可以使用消息工具栏中的“{}”按钮并将代码放在那里,以便更好地阅读。
关于您的问题,您在代码中遗漏了一些错误和错误。
如果您想在AutoIT中执行有关TCP / UDP的任何操作 - 首先需要启动他们的服务,然后关闭它们。
在许多编程语言中,字符串变量在字符串的开头和结尾需要两个“”。 AutoIT也一样。
使用 TCPSend 时,第一个参数是套接字,第二个参数是它将发送的消息。
这是我编写的一个示例脚本。随意修改它。我也评论了一些东西。
#Include <ButtonConstants.Au3>
#Include <EditConstants.Au3>
#Include <GUIConstantsEx.Au3>
#Include <StaticConstants.Au3>
#Include <WindowsConstants.Au3>
#Include <GUIEdit.Au3>
#Include <Misc.Au3>
#NoTrayIcon
Opt ('GUIOnEventMode', 1)
;We are using Input boxes so the user can type in the IP/Port/Msg and they will be stored as variables for later use
$IP = InputBox("SO TCP Connector", "Receiver's IP Address", "0.0.0.0", "", _
- 1, -1, 0, 0)
$Port = InputBox("SO TCP Connector", "Receiver's Port", "80", "", _
- 1, -1, 0, 0)
$Message = InputBox("SO TCP Connector", "Message to send", "Sample text", "", _
- 1, -1, 0, 0)
;Starting the TCP service
TCPStartup()
;Opening a socket
$iSocket = TCPConnect($IP, $Port)
;Sending our message
TCPSend($iSocket, $Message)
;Closing the socket from before
TCPCloseSocket($iSocket)
;Stopping the TCP Service
TCPShutdown()