[已解决]IP地址改变后端口监听失败是什么原因,如何解决?
本帖最后由 hlzxcjx 于 2011-11-13 23:28 编辑TCPStartup()
$ip = @IPAddress1
$Customerlsn = TCPListen($ip, 8843)
MsgBox(0, "$Customerlsn", $Customerlsn)
While 1
$Indextext = TCPAccept($Customerlsn)
$text = TCPRecv($Indextext, 2048)
If $text <> "" Then
;;;;;;;;;;;;;
EndIf
Sleep(1000)
If $ip <> @IPAddress1 Then
TCPShutdown()
Sleep(10)
TCPStartup()
$Customerlsn = TCPListen($ip, 8843)
MsgBox(0, "$Customerlsn", $Customerlsn)
EndIf
WEnd
当不断更改IP地址时,$Customerlsn=-1,监听失败,重启服务亦无效,如何解决? 端口是不是被占用了,没有释放,换其他的端口试试! 好像要用TCPcloseSocket()来释放端口 试一试
TCPStartup()
$ip = "0.0.0.0"
$Customerlsn = TCPListen($ip, 8843)
MsgBox(0, "$Customerlsn", $Customerlsn)
While 1
$Indextext = TCPAccept($Customerlsn)
$text = TCPRecv($Indextext, 2048)
If@error Then
TCPShutdown()
TCPStartup()
$Customerlsn = TCPListen($ip, 8843)
MsgBox(0, "$Customerlsn", $Customerlsn)
EndIf
If $text <> "" Then
;;;;;;;;;;;;;
EndIf
WEnd 端口是不是被占用了,没有释放,换其他的端口试试!
xms77 发表于 2011-11-12 21:44 http://www.autoitx.com/images/common/back.gif
我是想继续用原来的端口! 好像要用TCPcloseSocket()来释放端口
xms77 发表于 2011-11-12 21:46 http://www.autoitx.com/images/common/back.gif
试过无效! 试一试
TCPStartup()
$ip = "0.0.0.0"
$Customerlsn = TCPListen($ip, 8843)
MsgBox(0, "$Customerls ...
yeqing880 发表于 2011-11-13 11:05 http://www.autoitx.com/images/common/back.gif
我是想当不断更改IP地址时,仍然用原来的端口监听成功! 回复 6# hlzxcjx
你少了一句$ip = @IPAddress1的赋值语句,你一直在使用原来的IP当然会有问题了,以下代码测试成功!TCPStartup()
$ip = @IPAddress1
$Customerlsn = TCPListen($ip, 8843)
MsgBox(0, "$Customerlsn", $Customerlsn)
While 1
$Indextext = TCPAccept($Customerlsn)
$text = TCPRecv($Indextext, 2048)
If $text <> "" Then
;;;;;;;;;;;;;
EndIf
Sleep(1000)
If $ip <> @IPAddress1 Then
$ip = @IPAddress1
TCPCloseSocket($Customerlsn)
Sleep(10)
$Customerlsn = TCPListen($ip, 8843)
MsgBox(0, "$Customerlsn", $Customerlsn)
EndIf
WEnd 回复 8# xms77
一语惊醒梦中人! 回复 9# hlzxcjx
不要学习太晚,记得要结贴啊!
页:
[1]