我在旅行社工作,我們一直在使用Autoit。我們有一個使用Autoit製作的TCP服務器,但我們的客戶端無法工作。無法發送消息到TCP服務器
這裏的故障代碼
$port = 1942
$addr = 192.168.101.111
$connexion = TCPConnect($addr, $port)
TCPSend("bus has arrived")
TCPCloseSocket($connexion)
我在旅行社工作,我們一直在使用Autoit。我們有一個使用Autoit製作的TCP服務器,但我們的客戶端無法工作。無法發送消息到TCP服務器
這裏的故障代碼
$port = 1942
$addr = 192.168.101.111
$connexion = TCPConnect($addr, $port)
TCPSend("bus has arrived")
TCPCloseSocket($connexion)
歡迎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()
爲什麼使用輸入框? –
@AnneSkeitzig我說過它的一個例子,你可以使用和修改,如果你想。我正在使用輸入框來避免每次服務器更改其IP /端口時都必須編輯腳本,並且避免編輯新消息。 – Dragg
但它會工作,如果我使用'$端口= 1942'和'$ ip = 192.168.100.111'? –
看起來這個代碼不夠實際調查您的問題。另外請注意,您的格式化會導致自動系統考慮此垃圾郵件,因此您有第二個編輯理由。 –
@PaulStelian如何編輯? –