无法向 TCP 服务器发送消息
Cannot send message to TCP server
我在一家旅行社工作,我们已经使用 Autoit 一段时间了。我们有一个使用 Autoit 制作的工作 TCP 服务器,但我们的客户端不工作。
这是错误代码
$port = 1942
$addr = 192.168.101.111
$connexion = TCPConnect($addr, $port)
TCPSend("bus has arrived")
TCPCloseSocket($connexion)
欢迎使用 Whosebug。发布问题时,您可以使用消息工具栏中的“{}”按钮并将您的代码放在那里,以便更好地阅读。
关于您的问题,您在代码中遗漏了一些错误和内容。
当您想在 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()
我在一家旅行社工作,我们已经使用 Autoit 一段时间了。我们有一个使用 Autoit 制作的工作 TCP 服务器,但我们的客户端不工作。
这是错误代码
$port = 1942
$addr = 192.168.101.111
$connexion = TCPConnect($addr, $port)
TCPSend("bus has arrived")
TCPCloseSocket($connexion)
欢迎使用 Whosebug。发布问题时,您可以使用消息工具栏中的“{}”按钮并将您的代码放在那里,以便更好地阅读。
关于您的问题,您在代码中遗漏了一些错误和内容。
当您想在 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()