ilqar200 Posted March 20, 2023 Share Posted March 20, 2023 Hello. I am interested in using WCD_IPC in my automation . But i dont understood how to use it correctly. Let me describe my situation: I have one main script and child scripts that will be running from main script. I want child scripts to interact with main script i.e send variables values and receive variables values.So i need multidirectional data exchange between main script and child scripts but very important at the same time. So questions : Is it achivable with WCD_IPC ? If yes so please give some example how to send and receive data at the same time in main script and in child scripts . If it not achivable with WCD_IPC what IPC would you recommended to me to achieve multidirectional data exchange at the same time with simple usage UDF? I have found MailSlot but it is one directional. Thanks. Link to comment Share on other sites More sharing options...
Nine Posted March 20, 2023 Share Posted March 20, 2023 It is possible with WCD_IPC. In the UDF thread there is an example of how parent/child can interact between each other. You can also look at the example I provided there : With those 2 examples, try to create a script that describes more what you intend to do... “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...
ilqar200 Posted March 20, 2023 Author Share Posted March 20, 2023 (edited) 3 hours ago, Nine said: It is possible with WCD_IPC. In the UDF thread there is an example of how parent/child can interact between each other. You can also look at the example I provided there : With those 2 examples, try to create a script that describes more what you intend to do... I have tested WCD_IPC with server and 2 client scripts. It is working ok. Below is code that i tested Server script : #include <WinAPI.au3> #include <Array.au3> #include <WCD_IPC.au3> Local $hServer = _WCD_CreateServer () Local $aReq While 1 If _WCD_Server_IsRequestAvail () Then $aReq = _WCD_Server_GetRequest () _WCD_Send($hServer,$aReq[0],1,$aReq[1]) ConsoleWrite($aReq[0]&$aReq[1]) EndIf WEnd Client 1 script : #include <WinAPI.au3> #include <Array.au3> #include <WCD_IPC.au3> #include <MsgBoxConstants.au3> Local $hWnd = _WCD_CreateClient ("Test WCD Client 1") Local $hWndServer = _WCD_GetServerHandle () _WCD_Send($hWnd, $hWndServer, 1, '[Client 1' & ', Message1]' & @CRLF) Sleep(100) MsgBox($MB_OK,"Client 1",_WCD_Client_GetResponse ()) _WCD_Send($hWnd, $hWndServer, 1, '[Client 1' & ', Message2]' & @CRLF) Sleep(100) MsgBox($MB_OK,"Client 1",_WCD_Client_GetResponse ()) _WCD_Send($hWnd, $hWndServer, 1, '[Client 1' & ', Message3]' & @CRLF) Sleep(100) MsgBox($MB_OK,"Client 1",_WCD_Client_GetResponse ()) Client 2 script : #include <WinAPI.au3> #include <Array.au3> #include <WCD_IPC.au3> #include <MsgBoxConstants.au3> Local $hWnd = _WCD_CreateClient ("Test WCD Client 2") Local $hWndServer = _WCD_GetServerHandle () _WCD_Send($hWnd, $hWndServer, 1, '[Client 2' & ', Message1]' & @CRLF) Sleep(100) MsgBox($MB_OK,"Client 2",_WCD_Client_GetResponse ()) _WCD_Send($hWnd, $hWndServer, 1, '[Client 2' & ', Message2]' & @CRLF) Sleep(100) MsgBox($MB_OK,"Client 2",_WCD_Client_GetResponse ()) _WCD_Send($hWnd, $hWndServer, 1, '[Client 2' & ', Message3]' & @CRLF) Sleep(100) MsgBox($MB_OK,"Client 2",_WCD_Client_GetResponse ()) I run server script first and then run 2 child scripts simultaneously . I was able to receive/send messages to/from server script. But some important questions again arise for me In above example i tested with only 2 child scripts. In my automation i am going to use about 100 child scripts simultaneously. Because i will use many child scripts is there any chance that some messages (i.e data ) will lost between server script and child scripts ? If there is any chance of losing messages (i.e data) how to completely avoid messages (i.e data ) lost between server script and child scripts ? In above example i have used Sleep(100) function to able to receive server response. But i dont want to pause my child scripts . How i can code my child scripts without Sleep function to be able to them receive an answer from server ? Some important child scripts returns an array. Can server receive an array ? Also i dont understood how to get child script handle from server script. Say i run server script and now want to send some data to child script . How to do this ? As i understood server script can receive child script handle only if child sends some data . But how to know child script handle if i want to send data firstly from server ? Edited March 20, 2023 by ilqar200 Link to comment Share on other sites More sharing options...
Nine Posted March 20, 2023 Share Posted March 20, 2023 (edited) 3 hours ago, ilqar200 said: Because i will use many child scripts is there any chance that some messages (i.e data ) will lost between server script and child scripts ? No -- it is based on Windows messaging system -- no message should be lost 3 hours ago, ilqar200 said: How i can code my child scripts without Sleep function to be able to them receive an answer from server ? See example of UDF (look at Function WaitForResponse in child) 3 hours ago, ilqar200 said: Some important child scripts returns an array. Can server receive an array ? Convert the array into string with _ArrayToString to send and reconvert them into array with StringSplit on receive 3 hours ago, ilqar200 said: Say i run server script and now want to send some data to child script . How to do this ? In theory server needs to know if child is there, so you could just send to server a 1st acknowledge to let it know that child is ready to receive information from server. It makes the communication protocol more robust. Edited March 20, 2023 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...
ilqar200 Posted March 20, 2023 Author Share Posted March 20, 2023 1 hour ago, Nine said: See example of UDF (look at Function WaitForResponse in child) 4 hours ago, ilqar200 said: Excuse me but your WaitForResponse function doing the same thing as mine code above i.e it pauses child script with Sleep(100) function. As i said in previous message i dont want to use Sleep function because it pauses child scripts . Pauses in child scripts can cause with higher chance of message skipping by one of child script because there will be a lot of scripts and messages in between server and child scripts. I dont want use Sleep function in server script too. So how to avoid message skipping in this case without Sleep function ? I didnot understood of meaning $iData variable in _WCD_Send function. I read that it is number of request. What it does affect ? Can i use in all my _WCD_Send function calls $iData equal to 1 ? Setting value of $iData to 1 in all cases will cause problems in my automation ? I also didnot understood _WCD_Server_PeekRequest () function. When i must use this function ? As i understood all messages (datas) will come as a String type. So i need convert from String to needed type in my scripts ? Link to comment Share on other sites More sharing options...
Nine Posted March 20, 2023 Share Posted March 20, 2023 Never do a loop without a sleep in any IPC or GUI. It will take 100% CPU for nothing, you always need to put a sleep (10 is minimum) unless you are calculating something. But if you dont care about it, just remove the sleep in my example. $iData has not meaning in itself, it is just a manner to create your own protocol. You need to invent the way how client/server talks to each other. I am just offering a framework for you to develop around it. For example if $iData = 1 it may mean for you that the client Acknowledges it is ready. Dont bother with _WCD_Server_PeekRequest until you feel the need to use it. Now enough questions, start creating your scripts, and come with some tangible programs that we can discuss of. SOLVE-SMART 1 “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...
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