[comp.sys.next] starting remote apps

cfcgf@ux1.cts.eiu.edu (Chuck Fleming) (04/16/91)

I'm trying to start up and communicate (via Speaker/Listener)
with a NextStep application on a remote machine.  When I manually
launch the app on the remote machine, everything works fine.
NXPortFromName does its job and so I can get a handle on the
remote app.  The problem is that I don't know
how to start up the application on the remote machine (from 
within a NextStep application - which is
where I want to do it - on the local machine ) other than
executing
   system("rsh reis26 -l cfleming MyListener -NXHost reis27 &")
from the local machine. This works, but the display 
(the main window) appears on the local machine.  

I had hoped system("rsh reis26 MyListener &") would have worked.
Is there a problem with this second attempt because MyListener
displays a window on the screen?  Is this a problem since
neither Workspace.app or Workspace Helper are running on the
remote machine? 

I guess the basic question is: How can one start up a 
NextStep application on a remote machine (on which I have an
account)? I have set both machines to be public window servers.
For some reason I have to reset the preference (public
window server) every time I run the apps.  The selection doesn't
seem to remain even though the check box is checked.  

Thanks,

chuck fleming
cfcgf@eiu.edu
    
ps. Here's a bit of the code if it might help.

#import "SpeakerWindow.h"
#import "MyMessageSpeaker.h"

#import <appkit/Speaker.h>
#import <appkit/Listener.h>
#import <appkit/Panel.h>
#import <appkit/Application.h>
#import <appkit/TextField.h>

#import <strings.h>
#import <stdlib.h>

@implementation SpeakerWindow

// Set up the application's speaker.
- initContent:(const NXRect*)contentRect style:(int)aStyle   
      backing:(int)bufferingType buttonMask:(int)mask defer:(BOOL)flag
{
   MyMessageSpeaker *aSpeaker;

   self = [super initContent:contentRect style:aStyle   
      backing:bufferingType buttonMask:mask defer:flag];

   aSpeaker = [[MyMessageSpeaker alloc] init];
   [NXApp setAppSpeaker:aSpeaker];
   
   //************************************************************************
   // This seems to enable NXPortFromName (in sendText:) to work. But I don't
   // really want to see the output displayed on the local machine.
   // Start the application on the remote machine.  Put it in the background
   // so that we regain control. No password is needed since we have fixed
   // /etc/hosts.equiv  on reis26.
   system("rsh reis26 -l cfleming MyListener -NXHost reis27 &");
   //************************************************************************

//************************************************************************
// I would like to use something like this.  But it doesn't work.
//system("rsh reis26 MyListener &");
//************************************************************************
   return self;
}

// This method will attempt to send the message "setMyText::" to a remote
// application.
- sendText:sender
{
   int speakerResult, stringLength, anInteger;
   char *word;
   port_t remoteAppPort;

   // Get send rights to the port registered under the name "MyListener".  
   // Use NULL as the second argument if you want the local host.   
   remoteAppPort = NXPortFromName("MyListener", "reis26");   
   if (remoteAppPort != PORT_NULL)
   {
      // This should be done before each remote message is sent, because
      // the workspace manager may reset the appSpeaker behind your back.
      [[NXApp appSpeaker] setSendPort:remoteAppPort];      
   
      // Send the message to MyListener.
      stringLength = strlen([wordField stringValue]);
      word = malloc(stringLength+1);
      strcpy(word,[wordField stringValue]);
      speakerResult = [[NXApp appSpeaker] setMyText:word 
                                        returnValue:&anInteger];
      free(word); 
      
      // See if the remote application can handle the message. If it
      // can, it should send back the number of characters in the word
      // sent to it.  Put this result in the length field.
      if (speakerResult == 0)
         [lengthField setIntValue:anInteger];
      else
         NXRunAlertPanel("Error", "MyListener could not handle the message.",
	                  NULL, NULL, NULL);
   }
   else
      NXRunAlertPanel("Error","MyListener's port could not be found.",
                       NULL, NULL, NULL);
   			                
   return self;
}

@end