okay Posted January 25, 2020 Share Posted January 25, 2020 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 More sharing options...
Nine Posted January 25, 2020 Share Posted January 25, 2020 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. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
okay Posted January 25, 2020 Author Share Posted January 25, 2020 Thanks for you testing, that was the only modif I did too. I found the solution, I disabled the Windows firewall on the server and it has become instant. Link to comment Share on other sites More sharing options...
okay Posted January 26, 2020 Author Share Posted January 26, 2020 (edited) 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 January 26, 2020 by okay Link to comment Share on other sites More sharing options...
okay Posted January 26, 2020 Author Share Posted January 26, 2020 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 More sharing options...
Nine Posted January 26, 2020 Share Posted January 26, 2020 (edited) 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 January 26, 2020 by Nine “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
okay Posted January 26, 2020 Author Share Posted January 26, 2020 (edited) 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 January 26, 2020 by okay Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now