本帖最后由 lamant 于 2014-6-10 15:59 编辑
回复 1# lamant
服务端:(想实现每隔5秒就接收一次数据。如果接收不到、或者接收到的数据与“1”不一致,就标记+1;如果接收到的数据与“1”一致,就标记0。标记满5次以后自动退出并提示连接断开)
TCPStartup()
Local $iSocket = TCPListen( "127.0.0.1",65532)
If @error <> 0 Then Exit
Local $StringRev
Local $PLUSE = 1
Local $Plusecount = 0
AdlibRegister("_Timer", 5000)
While 1
Sleep(5000)
WEnd
Func _Timer()
$StringRev = TCPRecv($iSocket,1)
If $StringRev = $PLUSE Then
$PluseCount = 0
sleep(5000)
Else
$PluseCount += 1
sleep(5000)
If $PluseCount >= 5 Then
MsgBox(0,"提示","连接已断开")
Exit
EndIf
EndIf
EndFunc
TCPCloseSocket($iSocket)
TCPShutdown() |