SocketTools .NET Edition

Remote Command Protocol

The Remote Command protocol enables an application to execute commands on a server, with the output of the command returned to the client. The SocketTools control actually implements three related protocols: rexec, rshell and rlogin. The choice of protocols is determined by the port that is selected when a connection is established.

Initialization

Initialize
Initialize an instance of the class, loading the networking library and validating the development license. This method must be called before any properties are changed or any other methods in this class are called by the application.

Reset
Reset the internal state of the component. This can be useful if your application wishes to discard any settings made by a user and return that instance of the class to its default state.

Uninitialize
Unload the networking library and release any resources that have been allocated for the class instance. This method is automatically invoked when the class instance is disposed or goes out of scope.

Executing Commands

When executing commands remotely, there are two similar protocols that can be used. The rexec protocol enables a client application to execute a command on a server. Output from the command is returned to the client and the connection is closed when the command terminates. The client connects on port 512 and must provide a user name and password to authenticate the session.

The rshell protocol is similar to rexec in that it enables a client to execute a command on a server. Output from the command is returned to the client and the connection is closed when the command terminates. The client connects on port 514 and must provide a user name. The primary difference between the rexec and rshell protocols is that rshell does not require a password. Instead, it uses what is called "host equivalence" to determine if the client is permitted to execute commands as that user. On a UNIX based operating system, host equivalence is controlled by the /etc/hosts.equiv and the .rhosts file in the user's home directory. These files list the host names and user names which are permitted to execute commands using the rshell protocol. Consult your operating system manual pages for more information about how to configure host equivalence.

An important consideration when deciding whether to use rexec or rshell is how the server is configured and the type of command being executed. If there is no entry for the local host in the server's host equivalence tables, then the rexec command should be used instead of rshell.

When using rexec or rshell, it is important to keep in mind that although the command is executed with the privileges of the specified user, that user is not actually logged in. The user's login script is not executed and the program will not inherit the user's normal environment as it would during an interactive session. If you are connecting to a UNIX system, you should not attempt to execute programs which try to put standard input into raw mode; an example of this would be the vi editor. If you are connecting to a Windows system, you should not execute a program which uses a graphical interface. Only programs which read standard input and write to standard output are suitable for use with rexec or rshell.

Execute
Execute the specified command on the server. The rshell or rexec protocol is selected based on the port number that is specified. Output from the command will be returned to the client to be read. When the command terminates, the connection to the server will be closed.

Read
Read the output generated by the command. Your application would typically call this method in a loop until all of the data has been read or an error occurs.

Search
Search for a specific sequence of characters in the output returned by the server. The method returns when the sequence is encountered or when a timeout occurs. The data captured up to the point where the character sequence was matched is returned to the caller for processing.

Remote Login

The rlogin protocol is similar to Telnet in that it provides an interactive terminal session. The connection is closed when the user logs out or the shell process on the server is terminated. The client connects on port 513 and must provide a user name and terminal type. If there is an entry in the host equivalence tables for the user and local host, then the client will be automatically logged in and provided with a shell prompt. If there is no host equivalence, the client will be prompted for a password. The terminal emulation control can be used to provide ANSI or DEC VT-220 emulation services if needed.

Login
Establish an interactive login session which is similar to how the Telnet protocol works. If there is no host equivalence with the local host, you will be prompted for a password. Output from the session will be returned to the client, and when the client logs out the connection will be closed.

Read
Reads any output that has been generated by the program executing on the server. Once a connection has been established, users are typically given a command line prompt where they can enter commands to be executed on the server. If the server closes the connection, the Read method will indicate that with an error result and the client can disconnect from the server at that point.

Search
Search for a specific sequence of characters in the output returned by the server. The method returns when the sequence is encountered or when a timeout occurs. The data captured up to the point where the character sequence was matched is returned to the caller for processing.

Write
Send data to the server which will be received as input to the program. In most cases, the server will automatically echo back any characters written as data to be read by the client.