Jump to content

Issue with TCP


okay
 Share

Recommended Posts

 I have found a great example of using the TCP functions  in the documentation (example 1) :

https://www.autoitscript.com/autoit3/docs/functions/TCPSend.htm

 

I tried it on two PCs over a local network (Router's Wifi) but I have an issue.

The server receives the string "tata", but not immediately, the TCPRecv() returns after a delay of a few seconds after the client has sent the data. For my script, I need to capture the data sent as soon as possible.

 

Does anyone have know why is this happening and how to fix it? The client is on Windows 8 and the server on Windows 7. I guess it has something to do with TCPRecv() being blocking so the script only checks from "time to time" ?

Link to comment
Share on other sites

Tested over WiFi LAN, Win 7 (family edition) acting as server, and Win 10 client.  Instant transmission.  Only modif I made to the script example is to hard code the "server" ip.

Link to comment
Share on other sites

Actually I still have the problem, it isn't related to the firewall...

First of all the the example works perfectly fine (no delay) when no modif is done (except changing the server ip)

 

I did a modif, and it introduces a delay of about 10 seconds, so the problem must come from it.

 

The modif i did is that I changed the line

 

 

TCPSend($iSocket, "tata")

 

into

 

Local $hDLL = DllOpen("user32.dll")
   While 1
       If _IsPressed("4E", $hDLL) Then
           ConsoleWrite ( "Ready to send" )
           TCPSend($iSocket, "tata")
           ; Wait until key is released.
           While _IsPressed("4E", $hDLL)
               Sleep(250)
           WEnd
           ConsoleWrite("_IsPressed - L Key was released." & @CRLF)
      ElseIf _IsPressed("1B", $hDLL) Then
        MsgBox($MB_SYSTEMMODAL, "_IsPressed", "The Esc Key was pressed, therefore we will close the application.")
        ExitLoop
      EndIf
       Sleep(25)
   WEnd

   DllClose($hDLL)

I also added the

  #include <Misc.au3>

 

So the only difference is that instead of immediately sending "tata", we wait for the user to press L to do so.

The problem is the server receives the sting "tata" after about 10 seconds and I have no ide why. The "Ready to send" is displayed in the client's console immediately after pressing L, so why is the TCPSend instruction not executed immediately ?

Edited by okay
Link to comment
Share on other sites

After some research, it seems that TCP implementations don't send data immediately for performance reasons, and instead put in a buffer until it gets big enough, could that be the reason ? (in the exemple without modif the data is sent immediately because the connection is terminated after the send whereas we stay in the loop in my example).

It seems it can be disabled with "TCP_NODELAY", if that's the solution how can i call that DLL functino in autoit ? I guess i would need the handle for the Winsock library ...

Link to comment
Share on other sites

Opt ("TCPTimeout",$Delay) might be the reason.  But you should not wait for key pressed inside that loop.  Do it at the beginning of the sender script instead (before TCPConnect). 

Edited by Nine
Link to comment
Share on other sites

I will try that option, meanwhile I found a much easier way : I used UDP (exact same code) and it works perfectly (no delay). I think I don't need TCP, especially on a local network.

BTW I wait for key presses inside that loop because I want to send keystrokes to the server in real time (not just one key).

Edited by okay
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...