Javier Albinarrate - LU8AJA

  • Increase font size
  • Default font size
  • Decrease font size

VT-100 Terminal emulator for PHP

Print

 

Sometimes you have a legacy system, which works over Telnet using some kind of Terminal standard. Banks, big companies, telcos, etc have loads of these legacy systems, and as they are key business systems, they just don't want to change them because of the costs and problems involved. But every day you have more new systems, lots of them internet based, a simple example is an intranet to provide access to external personnel. So to make a long story short, there is an actual need to access the information available at those terminals from the intranet. The language I work with most of the time is PHP. And I promptly found that there is no extension, library, snippet, whatever to actually do that.

For sure you can make a simple Telnet connection, the problem is dealing with the terminal standard to actually render a virtual screen (a bidimensional array) from where you can extract the information using coordinates. If you "read" the bytestream of a connection with a complex "windowed" telnet application, you will soon find that with all those escape sequences, and the "feature" of updating only the screen differences, you will not be able to reliably extract information from the stream at all.

So, several years ago, I found myself in that situation and I had to write a library to do that. And it actually works! Laughing

The first thing you have to analyze is what Terminal Standard you need, because there are loads of them. But something you have to think of, is that the oldest the standard is, the easier to emulate the terminal. And specially in the case of the latest IBM standards like TN5250 and similar, which are really a mess (the don't even use ASCII). Now something you must be aware, is that during the Telnet negotiation, client and server decide which standard they will use, and another important thing is that almost all servers are backwards compatible with the older standards, like VT-100. This was the key to success. After verifying that there was no need to the advanced features of TN5250, I just started reading the Telnet standard (RFC854 and associated) and the VT-100 specs. And I just implemented them in the library, and voila, I was successfully rendering the screen, reading popups, writing in fields, making searches, crawling the menus, retrieving complex recordsets, etc.

There are many disadvantages when dealing with a terminal system, among others, the fact that you don't have signals to recognize events, like when the screen has been finished, or to recognize unknown popups which were not present when the interaction was programmed (something that a human would know what to do with it) and similar situations. For example, if there is an unexpected popup saying "Merry Christmas, please press Enter to continue", it can be really troublesome :)

So, after writing the terminal emulator, the next step was to provide simple ways to interact with such virtual screen, so I came up with triggers, rules, virtual screen definitions, etc.

The whole experience was enlightening, and I certainly learned a lot from it. The only curious thing is that I never found on the internet any comments on a similar need or solution.

You can download the emulator here: vt100.v1.rar

If you need help, just email me from the contact page.

 

Last Updated on Tuesday, 27 December 2011 09:47  

Google Translate

English French German Italian Portuguese Spanish