无法发送消息到TCP服务器

问题描述:

我在旅行社工作,我们一直在使用Autoit。我们有一个使用Autoit制作的TCP服务器,但我们的客户端无法工作。无法发送消息到TCP服务器

这里的故障代码

$port = 1942 

$addr = 192.168.101.111 

$connexion = TCPConnect($addr, $port) 

TCPSend("bus has arrived") 

TCPCloseSocket($connexion) 
+0

看起来这个代码不够实际调查您的问题。另外请注意,您的格式化会导致自动系统考虑此垃圾邮件,因此您有第二个编辑理由。 –

+0

@PaulStelian如何编辑? –

欢迎*上。在发布问题时,可以使用消息工具栏中的“{}”按钮,并将代码放在那里,以便读取更好。

关于你的问题,有几个错误和你遗漏在代码中的东西。

当你想在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() 
+0

为什么使用输入框? –

+0

@AnneSkeitzig我说过它的一个例子,你可以使用和修改,如果你想。我正在使用输入框来避免每次服务器更改其IP /端口时都必须编辑脚本,并且避免编辑新消息。 – Dragg

+0

但它会工作,如果我使用'$端口= 1942'和'$ ip = 192.168.100.111'? –