Using Personal Server

Personal Server Environment

"pnuts" command takes a short but significant time to start up. This is because the command starts a Java VM every time. Therefore, the pnuts command is not suitable for frequent use of small scripts.

In Personal Server environment this problem is eliminated by a program called pserv running as a network server and a lightweight client program psh which is used on the same machine.

How It Works

psh reads scripts from a file or user's terminal and send it to the server. pserv accepts the user input and execute the script. Then it sends the result back to the client. After the server finishes the execution, psh receives the result and displays it. psh can start up quickly because it is written in C and the overhead of the network communication is quite small.

For security reason, pserv's service should be protected from other users. In the Personal Server environment, psh sends a cookie with the scripts every time. When pserv starts, it generates a random number, called cookie, and save it in a user's private file. psh read the number and send it to the pserv server every time.

Currently Solaris and Win32 versions are provided.

Windows (NT/98/95)

C:\PNUTS> pserv { -port number } { -home directory }

To start a personal server, execute pserv.bat from a DOS window or dubble click the batch file. Probably you need to change %PATH% and %PNUTS_HOME% in the pserv.bat. To stop the personal server, type Ctrl-C in the DOS window that pserv.bat opened.

When pserv starts, a subdirectory ".pnuts" is created under the directory of the "user.home" property. Then cookie file is created in it. The port number to which the server is listen and a random number are saved in the cookie file.

Since the Java property "user.home" is different from VM to VM, pserv command can accept "-home" switch to specify the base directory of the .pnuts/cookie file. If "user.home" of your JVM is different from the following standard definition, don't forget to specify '-home' option. You might want to edit the pserv.bat file to add the -home option.

platformcookie file
Windows NTC:\Winnt\Profiles\%USERNAME%\.pnuts\cookie
Multi-user Win95/98C:\Windows\Profiles\%USERNAME%\.pnuts\cookie
Single-user Win95/98C:\Windows\.pnuts\cookie
(*1)

C:\PNUTS> psh { -e expression | scriptFile {, arg1, ...}}
C:\PNUTS> pshw { -e expression | scriptFile {, arg1, ...}}

psh command executes the specified script or expression as a Windows console application. pshw does the same as a Win32 Application.

C:\> psh test.pnut
The following variables are defined in the personal server environment.
$cwd
the current directory name of the client
$args
an array of command line arguments

The following optional steps allow you to start a server and execute scripts by double clicking.

  1. Create a shortcut of pserv.bat and place it on the desktop or in the start menu.
  2. Right-click on the shortcut, select Properties, click the Program tab, and make sure the Close on Exit option is turned on.
  3. You might want to customize the icon.
  4. Select Options from the View menu in My Computer or Explorer, and click the File Types tab.
  5. Click add and specify the type desciption "Pnuts Script" for .pnut files, as well as the MIME type "application/pnuts".
  6. Create a new action "open" with the command "%PNUTS_HOME%\pshw.exe %1", where %PNUTS_HOME% should be customized for your configuration.
See Limitations.

Unix (Solaris)

pserv Command

% pserv start { -port number } { -home directory }
% pserv stop

pserv start command starts the service. If -port switch is not specified an unused port number is assigned.

% pserv start
port=55712

When pserv starts, a subdirectory ".pnuts" is created under the directory of the "user.home" property. Then cookie file is created in it. The port number to which the server is listen and a random number are saved in the cookie file.

Since the Java property "user.home" is different between platforms (*1), pserv command can accept "-home" switch to specify the base directory of the .pnuts/cookie file.

psh Command

% psh {{ -port number } { -e expression | script_file {, arg1, ...} } | -help }

psh command is the client side program of a Personal Server environment. If "-port" switch is given, it connects to the port on the local machine. Otherwise, the port number is read from the cookie file.

If -e option is given, the expression is evaluated. If script_file is given, the file is loaded. If neither script_file nor -e option is given, psh program reads scripts from the standard input.

% psh /tmp/test.pnut
%

On Unix platforms, if the first line of the script starts with "#!", the line is skipped so that the script file can be executable. The variable "$cwd" is defined as the current directory of the client. The variable "$args" is defined as an array of command line arguments. The following script is an implementation of echo command.

#!/bin/env psh

for (i = 1; i < $args.length; i++){
   println($args[i])
}

Limitations

There is no way to cancel a server-side task in the current version. When you try to quit a long running program with Ctrl-C, the server-side program will not be terminated.


Back