Writes data to a shared memory instance.
SharedMemWrite(mem-name, data, timeout)
(s) specifies the identifying name of an existing shared memory instance used in a previous call to SharedMemOpen.
(s/i/f/b) data number, string, or binary buffer to write to shared memory. Max size of data should not exceed 4088 bytes.
(i/f) timeout specifies the timeout period in seconds, or -1 to never timeout.
(i) returns @True on success, or @False when the function times out.
This function places integers, floating-point numbers, ANSI strings, Unicode strings, or binary buffers into shared memory for later access by scripts calling the SharedMemRead function. You can also write WIL variants to shared memory if the can easily be converted to one of those 5 types. The SharedMemRead function returns the variant data as one of the 5 types.
The fist time the function is called it writes data to shared memory as soon as it has excusive access. In subsequent calls using the same shared memory instance in the same script, the function waits until the SharedMemRead functions reads existing data or the timeout period is reached. This difference is necessary to prevent deadlocks.
The function signals any waiting SharedMemRead functions that new data is avaiable after it completes the write operation.
Mem-name
Mem-name must be identical to a name passed in a call to the SharedMemOpen function in the same script. The name must match both the characters and the case of a name passed to SharedMemOpen.
Data
An integers, floating-point numbers, ANSI strings, Unicode strings, or binary buffers not exceeding 4088 bytes.
Timeout
The period of time in seconds that the function will suspend the calling script after the first time data is written to named shared memory instance. The parameter can be either an integer or floating-point number. Use a floating-point number for partial second wait times. On the first call to the function the function only waits until it has exclusive access to the share memory instance.
;;------------ ;; GetUpTime.WBT ;;------------ IntControl(12,5,0,0,0);Terminate quietly CmdName = "UptimeCmd" ; Case sensitive DataName = "UptimeData" ; Case sensitive WriteTimeout = 30 ReadTimeout = 60 Notice = @crlf:@crlf:"[ Press CTRL+BREAK to exit script ]" BoxOpen("Uptime Client","Initializing connection to shared memory...") OK = SharedMemOpen(CmdName, @true) Terminate(!OK, 'Get Up Time', 'Shared memory command creation/open failed') OK = SharedMemOpen(DataName, @true) Terminate(!OK, 'Get Up Time', 'Shared memory data creation/open failed') ; Send a request for the server up time. Response = "nothing" Request = "SEND_UPTIME" ReqWait = 1 ;Wait for a response. While ReqWait ReqTimeout = SharedMemWrite(CmdName, Request, WriteTimeout) If !ReqTimeout BoxText(Request:" timed out without response.") Break EndIf BoxText("Waiting for a respones to request: ":Request:Notice) Response = SharedMemRead(DataName, ReadTimeout) If Response != "*NODATA*" || Response != "*TIMEOUT*" Request = "EXIT" SharedMemWrite(CmdName, Request, WriteTimeout) ReqWait = 0 EndIf EndWhile SharedMemClose(CmdName) SharedMemClose(DataName) Message("Uptime Example","Sever up time is ":Response:" exiting") Exit ;;------------ ;; ServerUpTime.WBT ;;------------ IntControl(12,5,0,0,0) ;Terminate quietly WriteTimeout = 30 ReadTimeout = -1 ; Forever. Starttime = GetTickCount64() CmdName = "UptimeCmd" ; Case sensitive DataName = "UptimeData" ; Case sensitive Request = "GET_UPTIME" Notice = @crlf:@crlf:"[ Press CTRL+BREAK to exit script ]" BoxOpen("Get Uptime Example","Initializing connection to shared memory...") OK = SharedMemOpen(CmdName, @true) Terminate(!OK, 'Get Up Time', 'Shared memory command creation/open failed') OK = SharedMemOpen(DataName, @true) Terminate(!OK, 'Get Up Time', 'Shared memory data creation/open failed') BoxOpen("Uptime Server","Initializing - Awaiting request ":Notice) ReqWait = 1 While ReqWait ; Wait for a request Request = SharedMemRead(CmdName, ReadTimeout) BoxText("Request received: ":Request) If Request == "*NODATA*" || Request == "*TIMEOUT*" Continue ; Not likely to ever get here ElseIf Request == "SEND_UPTIME" Uptime = GetTickCount64() - Starttime Response = Uptime/1440000:' days ':Uptime/60000:' min. ' Response := (Uptime mod 60000)/1000.0:' sec.' bWriteOk = SharedMemWrite(DataName, response, WriteTimeout) If !bWriteOk Then ReqWait = 0 Else BoxText("Sent uptime ":Response) ElseIf Request == "EXIT" ReqWait = 0 EndIf EndWhile SharedMemClose(CmdName) SharedMemClose(DataName) Message("Uptime Example","Exit command received. Server exiting") Exit