previous contents next
Previous: Some Useful Enif System Parameters Next: Calling the SEnC Program

Communicating with an Enif Server

Enif's server mode is activated by calling Enif with the command line option ``-S port'' (where port is the number of the TCP/IP port which is to be used by the server). The only difference, compared to running Enif not in server mode, is that this option will install an Enif TCP/IP server configurable object as a child object of the primary Enif instance. This server object binds itself to the specified TCP/IP port and waits for client programs to open a connection.

When a client opens a connection, an Enif socket object is created as a child of the server object and a communication stream is established between the external client program and the corresponding socket object. When created, this object only defines the standard parameters needed for all objects (such as name, description, group filters, ...), leaving it up to the client program to create additional parameters as needed.

The client program can now send commands to Enif which then will be executed within Enif and the result will be sent back to the client. The result always ends either with positive or negative acknowledge, usually ``OK'' to indicate a successful command, respectively ``KO'' to indicate that the command could not be executed correctly.

The complete list of Enif server commands along with detailed technical specifications can be found in [2]. Here, we will just mention some of the more important ones:

lp [parameter]
 
List the specified parameter or, if no parameter is given as argument, list all parameters of the current object.

new partype parname [elementtype]
 
Create a new parameter of type partype with the name parname. The most used parameter types partype are Click, Bool, Integer, Float, Expression, Selector, String, Stylus and Box. For parameters which need further specifications, these are given after the parameter name. For expressions and selectors, e.g., the type of network element they refer to is given by elementtype as Nodes, Links, Lines, Segments, Turns, etc.

delete parname
 
This command is used to delete the parameter parname which was previously created with a ``new'' command.

check expressionpar
 
Check if the given parameter expressionpar, which must be of type Expression or Selector, contains a valid expression. The type of acknowledgment (OK resp. KO) indicates if the expression is valid or not.

echo anytext
 
The given text anytext is passed through Enif's parameter substitution to replace occurrences of the type %<...>% and the result is returned to the client.

exit
 
Close the socket and terminate the communication stream between the client program and Enif. Note that this command does not terminate the Enif process.

Besides the above server commands, the server also accepts the standard parameter specification commands which we already encountered in an earlier section of this paper, namely:

parameter : sendgroup[/receivegroup[/updategroup]
  ] 
Set the group specification of parameter.

parameter = value
 
Set the value of a non-indexed parameter (resp. set value at index 0).

parameter[index] = value
 
Set the value of an indexed parameter.

Having learned about the Enif server commands, let's try them out now. Even without having access to a specific Enif client program, it is possible to do this using the standard telnet program.

To do this, just start Enif in server mode using e.g. port 9090 with the command ``enif -S 9090''. Now, from a unix shell or CMD window, you can contact the Enif server with the command ``telnet localhost 9090'' and try out some of the above commands.

The first example just changes the current view from its current setting to the coordinate window (-1,-1,1,1). To do this, a Box type parameter named view is created and its send group is set to $CurrentView/, i.e. the receive group of the corresponding system parameter. When we then change the value of the parameter view to ``-1,-1,1,1'', Enif's parameter grouping will propagate a send group signal which is caught by the $CurrentView system parameter, which causes Enif's view to be changed accordingly.

%telnet localhost 9090
Trying 127.0.0.1...
Connected to localhost (127.0.0.1).
Escape character is '^]'.
OK
new Box view
OK
view : $CurrentView/
OK
view= -1,-1,1,1
OK
exit
Connection closed by foreign host.
% 
Image fullview
Image newview

The second example contacts the enif server to generate a list of all links having an auto volume of more than 3000, sorted according to decreasing link volumes. To do this, a link expression parameter named linkval and a link selector parameter named linksel are created and their values are set to the desired expressions. The check command is not absolutely necessary, but it would show if the specified expression would not be valid (e.g. if the current scenario would not have an auto assignment). The eval command, finally, is used to evaluate the expression linkval by iterating through all links selected in selector linksel and the corresponding results are output:

% telnet localhost 9090
Trying 127.0.0.1...
Connected to localhost (127.0.0.1).
Escape character is '^]'.
OK
new Expression linkval Links
OK
new Selector linksel Links
OK
linkval = volau,volad,timau,speedau
OK
check linkval
OK
linksel = volau>3000,-volau
OK
eval linkval linksel
609-608;3329.708;55;2.508259;8.133132
458-59;3209;0;1.2;10
705-713;3140.356;23.07692;0.617797;11.65431
611-610;3132.645;55;2.741341;10.06806
665-674;3105.219;0;0.811095;23.67171
668-665;3105.219;0;1.066585;12.37595
669-668;3105.219;0;1.308991;12.37595
516-608;3035.614;29.79895;0.454977;26.37496
517-516;3035.614;29.79895;0.432228;26.37496
607-606;3027.583;159.174;1.369371;10.07762
610-609;3016.525;55;1.423182;11.38294
OK
exit
Connection closed by foreign host.
% 

These two little examples using telnet should already give you an idea on the principles Enif's server is built upon. We now turn our attention to SEnC, a simple Enif client program which processes server commands that are read sequentially from given input files.


previous contents next
Previous: Some Useful Enif System Parameters Next: Calling the SEnC Program

SEnC - A Sequential Enif Client, Heinz Spiess, May 2003