General usage (important)

Top  Previous  Next

RW NetServer has generally been created, so it closely matches how RW Net performs it's calculations. There are, however, several changes due to the server environment. These are described here, but even if you are not familar with RW Net, you should read this chapter carefully.

 

When the server is started one or more networks are loaded into RAM. In order to use one of these, a calculation object is created and attached to one of the networks. The calculation object is used for most of the actual routing calculations.

 

Some calculations can however be executed directly on the network object and require no calculation object. Network objects are stateless and are typical rather simple lookup functions for returning information about the network (length of links etc), but can also be more complex functions like spatial searches (coordinate2node function for instance).

 

You get access to the objects by calling one of the services:

 

Services

 

The server makes 4 services available for use by the clients:

 

RW_NETMGMT

Stateless service, uses the number of the network as first parameter in function calls.

Gives access to 6 functions: CloseLink, SetLinkSpeed, SetLinkTime, CalcOptimumAlpha, KillAllIdState and ReloadNetwork.

These functions are special because they change values on the given network and the precalculated Alpha value.

The changes in the network can optionally be made persistent (Pro only).

As this service is generally a management type service, its usually not accessed by the 'general public', but only by administrators.

In the supplied sample configuration file this service is disabled.

 

RW_NETBASE

Stateless service, uses the number of the network as first parameter in function calls.

Gives access to the rest of the functions in rwnetbase class.

 

RW_NETCALC

Statefull service, uses network 1 by default, can be overridden with function SetNet

Gives access to functions in the main rwcalc class - this is the service, that you will be using most.

 

KBMMW_INVENTORY

Stateless service. This service can optionally be enabled to let clients query the server for the servers functionality.

As the service is stateless, and its functions (LIST, GET VERSION, GET AUTHOR, GET ASSISTANCE, GET DESC ABSTRACT, GET DESC DETAILS, GET SYNTAX ABSTRACT, GET SYNTAX DETAILS) are very lightweight, it can for example be used to poll to ensure a client still have a valid, operational connection to the application server.

 

Function parameters

 

Parameters to functions are passed as arrays of variants and results are returned in the same way. Results passed as "by reference" in RW Net are also returned as part of the variants array.

 

If the result is a single value, it is returned as a variable (integer for instance) and not as an array with a single element.

 

Function parameters - GIS files

 

Some functions return a GIS file (SHP for instance) as part of the result, which can be shown on a map. The server decides the (unique) name of the file and return this as a part of the result, the last parameter in the variant array (without extension). This is true for these functions: IsoLink2, IsoLink2Dyn, IsoLink4, isoPoly1new, IsoPoly2, IsoPoly3, IsoPoly4 and RouteList.

 

Generated GIS files can be streamed to the client by using the GetFile function. This allows you to create GIS files at the server and send them to the client. This is especially usefull, when server and client is not on the same computer or are otherwise on different networks.

 

Generated GIS files can also be accessed as an array from the client. This may be the best option if none of the current GIS files matches your need.

 

Routing mode

 

By default RW NetServer uses fastest path calculation (SetFastest) as opposed to RW Net, which has no default routing mode.

 

StateID

 

It is important to understand the concept of StateID in the server:

 

Property stateID refers to the instance of the service you want to use.

Calling a statefull service with stateID = -1 will create a new instance of the service on the server and update property stateID for reference.

Calling a statefull service with stateID <> -1 will make the server re-use that instance.

Calling a stateless service will ignore the stateID setting, but it will be set to -1 afterwards !

 

Thus its very important to record the returned stateID and reuse that for subsequent calls to the server. If not, new instances will be generated all the time, which at some point makes the server reach its limits after which clients will not be able to get new service instances.

 

The safe way to do it is to call RW_NETCALC service with -1 as parameter the first time, record the generated stateID and then supply that stateID in all future calls like this:

 

RW.SendRequestEx("RW_NETCALC", "", -1, "NODELISTSET", v_in, v_out)

sid = RW.StateID

RW.SendRequestEx("RW_NETCALC", "", sid, "NODELISTSET", v_in, v_out)

RW.ReleaseState

 

If you don't call any of the stateless services, you can also do it like this:

 

RW.StateID = -1

RW.SendRequest("RW_NETCALC", "", "NODELISTSET", v_in, v_out)

RW.SendRequest("RW_NETCALC", "", "NODELISTSET", v_in, v_out)

RW.ReleaseState

 

Here the first call to sendrequest will generate a new instance of the RW_NETCALC service (since StateID is -1) and StateID property will be updated accordingly. In the next call to sendrequest, the new StateID will be used. When calling ReleaseState the stateID property will be used again.

 

Sample code

 

Have a look at some of the sample code supplied with the various clients to see, how it works in practice. The samples for Asp, MS Excel, Java and PHP are most complex and show most areas of the client access.

 

Even more complex setups can be found in the RW Net documentation.

 

Also refer to the main reference section of this document.