Version 3.7 introduces the ability to function as a server, which allows other programs can communicate with the simulator. With this feature it's possible to interface external devices or to use utility programs toe make the simulation even more real. The server feature will send all text lines received to the main command handler. This handler is the same that is already used for triggers and for the "do" command in the scripts. Therefore, most of the actions that can be executed through a trigger or a script now can be executed through the server interface.

In addition to receiving commands, Train Director also sends messages to the remote program any time the user interacts with the program, for example throwing switches or clearing signals.

Therefore, the remote program can now make decisions based on these event notifications.

This new feature opens up new scenarios, such as:

  • To control Train Director fron a physical control bench. Indeed, this has been the main reasin why I implemented this feature, since some user had expressed interest in building their own control bench (of course at the amateurial stage).
  • to connect 2 or more simulators to control a scenario by more than one person. Although this requires the use of an additional program to distribute the various events to the connected programs, this is now possible without having to change the Train Director sources.
  • It may be possible to automate a simulation simply by recording all the events as the user proceeds in the simulation, and then to send them back to Train Director through the server interface.
  • it is now possible to use other programming languages to interact with Train Director, such as perl, python, Visual Basic or C#. It is not necessary anymore to learn C or C++ and to know the intricacies of the Train Director sources (part of which have been written over 10 years ago!!!).

How to Use the Server Interface

When Train Director starts, it opens a socket connections on port 8900. An external program can connect to this port and it can communicate with Train Director by sending simple commands.

On Windows one can use the DOC command "telnet", or the free terminal emulator PuTTY using the following configuration to connect to Train Director:

On Linux and MacOS X one can use telnet to connect to the server:

  $   telnet localhost 8900
In any case, once the connection is established, it is possible to send commands to the simulator:

The command list is shown in the scripts page.

If the player operates on the simulator through the graphical interface, for example by clicking on a switch, an event will be sent to the connected program with the simulated time when the event occurred, followed by the command that describes the event:

This is all for now. It's possible that in the future I will add more events and commands to cover new cases, although in this case this will be done in a backward compatible way.


This page is maintained by g_caprino@gmail.com
(Remove the _ before sending the message.)
Created on: May 15, 2010