JohnNash

TCP connection slows down after a while

8 posts in this topic

I am connectin a autoit code on my machine with an autoit code on my virtual machine.  It works mainly by instructing eachother through TCPSend and receive. All well, all good. Runs like a train. We however notice on every occasion that a certain action that is triggered by such a message slows down in reaction time after an hour or so. 

We personally suspect is has something to do with the fact that we send a lot of messages both ways and some buffer might get full or something like that? We googled for TCP flush/buffer + autoit but found nothing conclusive ... any idea? Should we clear something?

Share this post


Link to post
Share on other sites



Bad implementation of TCP in one or both of your scripts.

Share this post


Link to post
Share on other sites

:D Yes I also suspect that. 

Minimal example (hope I didnt delete too much)

 

 

MINIMAL CLIENT.au3
;communication======================================================================
Global $MainSocket
Local $MaxLength = 512              ;Maximum Length Of Text
Local $Port = 8080                  ;Port Number
Local $Server = "xxx"


TCPStartup()                        ; Start the TCP service.
$MainSocket = TCPConnect($Server, $Port)
If $MainSocket = -1 Then Exit MsgBox(16, "Error", "Unable to connect.")



;MAINLOOP?**********************************************************************************************************************************************************************
While 1
Local $fDiff = TimerDiff($hTimer) ; What is difference between time now and
   $Data=0
   $Data = TCPRecv($MainSocket, $MaxLength)
 ; MsgBox(16,"MessageDebug",$Data)
   If $Data = "ByeBye" Then
   MsgBox($MB_SYSTEMMODAL, "Closing Down Client and Server", "Shutting Down", 1)
   Terminate()
   EndIf



If CountInstances() < $sAnswer And $fDiff > 15000 Then
      OpenNewInstance()

         sleep(500);safety loop

      EndIf

      WEnd
;*******************************************************************************************************************************************************************************






Func OpenANewInstance()
  $hTimer = TimerInit() ; Begin the timer and store the handle in a variable.
AcutalOpeningOfinstance(); here we open something on Client
;HERE we check whether it is opened (omitted)

TCPSend($MainSocket, "Server do your Thing")

While 1
    $Data = TCPRecv($MainSocket, $MaxLength)
    sleep(100)
    If $Data = "Client please Continue" Then
    
    ExitLoop
    EndIf
WEnd


EndFunc
MINIMAL SERVER. au3



Global $MainSocket = -1
Global $ConnectedSocket = -1
Local $MaxConnection = 1; Maximum Amount Of Concurrent Connections
Local $MaxLength = 512; Maximum Length Of String
Local $Port = 8080; Port Number
Global $Server = InputBox("Question", "IP", "xxxx", "", _
             - 1, -1, 0, 0)

TCPStartup()
$MainSocket = TCPListen($Server, $Port)
If $MainSocket = -1 Then Exit MsgBox(16, "Error", "Unable to intialize socket.")

Global $switch = 0
While 1


 If $ConnectedSocket = -1 Then
$ConnectedSocket = TCPAccept($MainSocket)
endif
   
$Data = TCPRecv($ConnectedSocket, $MaxLength)
            If $Data = "ByeBye" Then
            Terminate()
            ;MsgBox(16, "Session Ended", "Connection Terminated.")
            ;Exit


            Elseif $Data = "Server do your Thing" Then
        
            ;Here We do Stuff and then
                        TCPSend($ConnectedSocket, "Client please Continue") 

            EndIf

 WEnd

 

Share this post


Link to post
Share on other sites

I deleted some stuff, for example $sAnswer is a number of instances of a certain program we want to have opened. Note that the sending and receiving works well initially and the code runs as expected. But like i said, it will slow down after an hour, and becomes slower and slower.

 

Share this post


Link to post
Share on other sites
35 minutes ago, JohnNash said:

$sAnswer is a number of instances of a certain program we want to have opened

each instance needs resources and so i am not wondering when pc slows down. 

Share this post


Link to post
Share on other sites
Just now, AutoBert said:

each instance needs resources and so i am not wondering when pc slows down. 

Hmm but they are also closed after it served its purpose. So never are there more instances open than 3 for example. Plus, in the beginning everything runs smoothly. I really noticed it is the sending  + receiving of the command that gets delayed. But no clue why

Share this post


Link to post
Share on other sites

Have you taken a look at Task Manager? Make sure you click 'Show processes from all users' and have a look and see if there is any high CPU/Memory loads from particular processes. You can then trace these back to particular services for instance is svchost.exe is using up a lot of resource, you can then break this down.

 

It does sound to me like some handle or other isn't being closed and freed up properly after use.

Share this post


Link to post
Share on other sites

Thanks, yes in the mean time I checked, but saw nothing special. Does anyone see something peculiar about my code?

I googled some more and found some articles about bufferbloat, could that be relevant?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now