Messaging between sessions?

Discussion of Inner Space

Moderators: Lavish Software Team, Moderators

Post Reply
mistahmikey
GamingTools Subscriber
Posts: 29
Joined: Wed Jun 30, 2010 7:48 am

Messaging between sessions?

Post by mistahmikey » Fri Mar 14, 2014 6:50 am

Is there a way to send messages between sessions? What I would like to be able to do is query another session for information, and have that information returned. Something like the following:

**** From a script running in session is1:

OnSessionMessageReceived[MessageReceived]

...

Uplink Send is2 "My Information Request"

...

atom MessageReceived(string SendingSession,string Message)
{
<process Information Request Reply in ${Message}>
}

*** From a script running in is2:

OnSessionMessageReceived[MessageReceived]

...

atom MessageReceived(string SendingSession,string Message)
{

<process Information Request in ${Message}>

Uplink Send ${SendingSession} "My Information Request Reply"
}

Lax
Owner
Posts: 6634
Joined: Fri Jun 18, 2004 6:08 pm

Post by Lax » Fri Mar 14, 2014 7:01 am

The command is "Relay" and does not need to be passed through Uplink.

Code: Select all

relay is2 "My Information Request"

The command is documented under the Uplink section but you do not need to pass it through Uplink.
https://www.lavishsoft.com/wiki/index.p ... Command%29

mistahmikey
GamingTools Subscriber
Posts: 29
Joined: Wed Jun 30, 2010 7:48 am

Post by mistahmikey » Fri Mar 14, 2014 7:44 am

Yep, I am aware of relay - use it a lot. So I realize I can use relay to run a script in another session that would perform the request. The problem I have is getting the response back to the calling script easily. I suppose I could use global variables in the requesting session and have the responding session use relay to call a script in the sending session that updates them, but the requesting script would then need to poll for the response event. I was just looking for a more direct way for the requesting script to receive the reply - something like the event callback I suggested (which would need to also be parameterized by the calling/responding script name, which I forgot to include).

mistahmikey
GamingTools Subscriber
Posts: 29
Joined: Wed Jun 30, 2010 7:48 am

Post by mistahmikey » Fri Mar 14, 2014 7:51 am

Upon further reflection, using relay as I described above could be problematic if multiple sessions make the same request to a particular session, since only one instance of a script can run. So, since I assume the feature I suggested is not available, can you suggest an alternative approach to achieving the sort of inter-script communication I desire using existing features?

Lax
Owner
Posts: 6634
Joined: Fri Jun 18, 2004 6:08 pm

Post by Lax » Fri Mar 14, 2014 10:38 am

Have a script running already that handles it, and pass in the source session name.

Code: Select all

relay is2 somecommand "$&#123;Session&#125;" "My information request"
and already running in is2 is a script with ....

Code: Select all

atom&#40;global&#41; somecommand&#40;string command_source, string command_type&#41;
&#123;
    echo Got a request '$&#123;command_type&#125;' from source '$&#123;command_source&#125;'
   
; respond to request
   relay "$&#123;command_source&#125;" somecommandresponse
&#125;

mistahmikey
GamingTools Subscriber
Posts: 29
Joined: Wed Jun 30, 2010 7:48 am

Post by mistahmikey » Fri Mar 14, 2014 6:11 pm

Aha - had no idea you can use relay to execute a global atom in the target session. I believe I can use this technique to do what I want to do. Thanks very much.

Post Reply