Sign in to follow this  
Followers 0
joseLB

process 2 process communication

3 posts in this topic

Hi

I have being searching forum for an UDF that implements process to process comunnications, and was unsucessful.

But my guess is that there is something about it, as this probably is used by many people.

So, I devised (didn't implement) the functions that follows, and:

1- could you tell me if there is something similar or better, but somewhat simple to use already done?

2- if I go to implement, I'm thinking into use ENVGET and ENVSET as the low level comm. mechanism. Do you sugest another way?

for what I read at help, these routines just works on "programs that AutoIt spawns (Run, RunWait). " That's somewhat limiting...

for what I read at forum they are not exactly a hi speed channel, that's another limiting factor.

3- any other advice / suggestion?

Thanks

Jose

Func _p2pInit ($channel, $buffers=2)
; #FUNCTION# ============================================================================
; Name...........: _p2pInit
; Description ...: creates a channel for communications betwen 2 or more processes. 
; Syntax.........: _p2pInit ($channel,[$buffers=2])
; Parameters ....: $channel - string with a unique name for the channel.
;   $buffers - optional - number of buffers used by this channel. Minimum 2.
;      These buffers are used in a circular manner
;
; Return values .: 1 - channel created
;   0 - error - channel was not created (it could exist previously) 
;      in this case it's just a warning and can be used -> see @error = 1
;   @error: 0 ok
;       1 - channel already exists
;       2 - invalid channel name or number of buffers
; =======================================================================================
EndFunc

Func _p2pSend ($channel="",$msg, $ansChannel=-1)
; #FUNCTION# ============================================================================
; Name...........: _p2pSend
; Description ...: send a message thru a given channel
; Syntax.........: _p2pSend ($channel,$msg, [$ansChannel=-1])
; Parameters ....: $channel - string with  channel name. It must be previously created by _p2pInit
;   $msg - message to be send. If $message= -1, all pending messages are cleared on that channel
;   $ansChannel (optional)- string with the name of another previously created channel, 
;      so the receiver can answers to this message.
;      (Sender and Receiver must agree (have the logic) on $ansChannel mechanism)
;
; Return values .: 1 - message sucessfuly sent
;   0 - error 
;   @error 1 -> channel does not exists
;       2 -> no avaiable buffer (the other partie didn't consume messages in a speedy manner)
; =======================================================================================
EndFunc

Func _p2pGet($channel, $timeout=5, %ByRef $ansChannel=-1)
; #FUNCTION# ============================================================================
; Name...........: _p2pGet
; Description ...: receive a message from a given channel
; Syntax.........: _p2pGet($channel, [$timeout=5])
; Parameters ....: $channel - string with  channel name. It must be previously created by _p2pInit
;   $timeout - default =0 -> waits up to this amount of seconds for a message to arrive. If 0, not wait
;   $ansChannel (optional)- string where the receiver can get the name of a previously created channel, 
;      if he intents to answer about this message to the sender. 
;      (Sender and Receiver must agree (have the logic) on $ansChannel mechanism)
;
; Return values .: string with message received
;   0 - error
;   @error 1 -> channel does not exists
;       2 -> no message exists (valid only if $timeout = 0)
;       3 -> timeout (no messages arrived)
;remarks:   
;   - a receiver can receive messages from many senders
;   - thru $ansChannel a receiver can send relplies to a specific sender/message
; =======================================================================================
EndFunc

Share this post


Link to post
Share on other sites



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
Sign in to follow this  
Followers 0