Pragma TelnetServer has implemented means for third party developers to take control of the telnet socket to communicate with the client directly. This is ideal for custom applications to send signals such as bells to the client, and to print output directly to client printers. Many handheld devices require a direct communication to print to its local printer.
The InetD socket handle is stored in the system variable PRAGMASYS_INETD_SOCK. Use the variable in any program to write and read information directly from the socket controlled by InetD. This variable will only be available in a program launched by InetD.
Programming for a telnet session is slightly different. The first thing is to confirm that the program is in a telnet session, using the above variable, plus the variable PRAGMASYS_TELNETD_PID. If either of these system variables are not present, then the program should fail or run as though it were not in a telnet session.
After confirming that the program is in a telnet session, the program should take control of the socket. This is done by inserting the TelnetServer PID into the string TelnetDInput%PRAGMASYS_TELNETD_PID%Mutex and TelnetDOutput% PRAGMASYS_TELNETD_PID %Mutex. Make the appropriate language call to open each mutex semaphore. The calls in C are:
hTelnetDOutputMutex = OpenMutex( SYNCHRONIZE, FALSE, TelnetDOutputMutexName);
hTelnetDInputMutex = OpenMutex( SYNCHRONIZE, FALSE, TelnetDInputMutexName);
After successfully taking control of the socket, the program can make the appropriate calls to the socket.
Once the program is ready to return control to TelnetServer the mutex semaphore must be released. This is done in C with the following calls:
ReleaseMutex(hTelnetDOutputMutex);
CloseHandle(hTelnetDOutputMutex);
ReleaseMutex(hTelnetDInputMutex);
CloseHandle(hTelnetDInputMutex);
Full code is available when the installation component Programming Examples is installed, or on the CD in the Examples directory. The file netio.c contains the code that uses the InputMutex and OutputMutex. The project builds a program called telwrite.exe, which is also included with the examples. This program can be used by an application, without any of the above programming requirements. Add a system call to the telwrite program with the appropriate options.