Webserver

Overview

FlexSim's Webserver is a Node.js-based, query-driven manager and communication interface for FlexSim. It allows you to run FlexSim models through a web browser like Google Chrome, FireFox, Microsoft Edge, etc.

The WebServer has its own installer which can be downloaded from your Autodesk account at manage.autodesk.com/products. Open your FlexSim product and find the webserver under the Extensions section. The installer includes a flexsimserver.bat launcher that installs Node.js (if needed) and starts the webserver.

When you start the FlexSim Webserver using the desktop shortcut, your computer will begin to host a website that looks like this:

By default, this website can be accessed by typing http://127.0.0.1:8080/ into a browser (the default port is 8080; see Configuration to change it).

Each user who starts model instances must be licensed individually. In the default login licensing mode, users sign in with their Autodesk account before starting or connecting to instances. In network mode, each browser session is assigned a server-computed fingerprint used for FlexNet license checkout. See Per-User Licensing for details.

Configuration

The webserver has various settings that can be adjusted in a configuration text file before starting it. The default location for the configuration file is C:\Program Files\FlexSim Web Server\flexsim webserver configuration.txt

<a id="this-file-needs-to-be-in-the-same-directory-as-flexsimserverbat"></a>
        # This file needs to be in the same directory as flexsimserver.bat

        General:
            Flexsim Program Directory:      %PROGRAMFILES%\FlexSim 2027\program
            Model Directory:                %DOCUMENTS%\FlexSim 2027 Projects
            Port:                           8080
            Reply Timeout (milliseconds):   10000
            Max Instances (of Flexsim):     8
            Max Threads Per Instance:       max
            Ignore Auto Save Files:         yes
            Headless Instances:             yes
        Remote Operations (security hazards):
            Model Uploading:                no
            Model Downloading:              no
            Model Deleting:                 no
            Max Upload Size (bytes):        10000000
        Jobs:
            Flexsim Data Directory:         %AllUsersProfile%\Autodesk\Flexsim\FlexSim27.0
            Max Job Queue Length:           100
            Max Job Timeout (seconds):      3600
        Windows Authentication:
            Use Windows Authentication:     no
            Restrict UserGroup Directories: no
            Active Directory:
                url:                        ldap://dc.domainName.com
                baseDN:                     dc=domainName,dc=com
                username:                   specialUser@domainName.com
                password:                   password
        Session:
            Secret:                         flexsim secret
            Max Age (seconds):              86400
        Admin:
            Api Key:                        none
        Licensing:
            Mode:                           login
            Redirect URI:                   http://localhost:8080/auth/callback
            License Servers:

General

Remote Operations

Jobs

Windows Authentication

Windows Authentication is optional and independent of licensing in both login and network modes. When enabled, it supplies a Windows identity on each request used only for Restrict UserGroup Directories.

Session

Server-side sessions are always enabled. Instances started by a session are only accessible by that same session. The session cookie is refreshed on each request (rolling expiration).

Admin

Licensing

Per-User Licensing

Each FlexSim instance started through the webserver is licensed to an individual client. The webserver identifies the client and passes licensing credentials to flexsim.exe at startup; license entitlement is enforced by the FlexSim engine.

Login Mode

The default mode for multi-user browser access. Each user signs in with their Autodesk account (APS three-legged OAuth via the FlexSim PHA proxy) before starting instances or submitting jobs.

Network Mode

For FlexNet network licenses checked out per browser session. Each browser session is assigned a fingerprint derived from User-Agent, Accept-Language, and remote IP. The fingerprint is stored on the session and passed to FlexNet as the licensed identity, so each seat maps to a browser session rather than a named Windows user.

FlexSim license type on the host

On the machine where FlexSim runs (the webserver host), network mode requires that FlexSim itself is configured for network licensing. After installing FlexSim, start the application once. On the Let's Get Started screen, select Use a network license, then enter your license server address when prompted (for example, 27000@license.example.com).

This step is not required for login mode. Sign-in licensing uses the Single-user license type on the host; entitlement is handled through the webserver's Autodesk sign-in flow instead of FlexNet checkout at instance startup.

To change the license type later, use Manage Licenses from the account menu in FlexSim and choose Change License Type to return to the Let's Get Started screen.

Job Queue and Licensing

The job queue (submitjob) is supported in both modes. Each job records the submitter's identity (APS session in login mode, browser fingerprint in network mode) and runs under that identity when dequeued.

Admin Page

Open /admin.html to view and close any running interactive instance or queued or running job on the server. The admin page does not start or connect to instances. Job-spawned instances are managed from the job queue only.

Set Admin.Api Key in the configuration file. Every admin request must include that value as the X-Admin-Key header. The admin page prompts for the key and stores it in the browser tab's session storage for the current session.

When no API key is configured (or it is set to none), admin API routes return HTTP 404.

Admin API Routes

System Requirements

Because the Webserver is actually running FlexSim models and rendering the graphics, the system requirements for the Webserver are the ​recommended system requirements for FlexSim itself. In addition, the Webserver must also compress and stream the graphics, dashboards, etc., so if anything, it is doing a bit more processing than a normal run of FlexSim. Add to that the fact that multiple people can log in and run models simultaneously, and the necessary system resources multiply accordingly.

FlexSim Webserver on a Virtual Machine

Virtual Machine platforms have not generally supported 3D graphics acceration without specialized hardware and/or software configurations. Without graphics acceleration, a system will not meet FlexSim's minimum requirements. VM platforms are evolving, and more and more are able to accelerate some 3D workloads. Please check your platform's 3D acceleration features to see if they meet ​FlexSim's minimum graphics requirements for OpenGL version.

Between the high hardware requirements and the use of accelerated graphics, FlexSim has not extensively tested the Webserver in virtual environments. While you may be able to create a Virtual Machine environment where FlexSim works well, you may also encounter issues that are VM-specific that have not been tested. As such, we do not recommend running the FlexSim Webserver in a Virtual Machine, particularly when using the Video Streaming mode instead of WebGL Streaming.

Key Concepts

When Licensing.Mode is login, sign in with your Autodesk account using the Sign in link at the top of the page before starting instances. The bar shows your signed-in identity and a Sign out link when authenticated. In network mode, the bar shows a short client identifier instead; there is no sign-in or sign-out flow.

To start a new instance of FlexSim, select a model to run and click Start New Instance. The Start New Instance button will gray out until FlexSim has started and the model is open. Once that occurs, the drop down under Running Model Instances will populate with the newly created instance. Select the instance and click Connect To Instance to view the automatically generated web interface for your model. Our Test Model had a 3D view and a Dashboard open side by side:

The interface that is displayed will match the interface of the model. You can rearrange the interface the same way you interact with FlexSim's windows. Click and drag on the window's tab to undock it, or right click and select Float. You can also close views by right clicking the window tab and selecting Close. Once undocked, you will see options for docking that window in various locations in the interface.

The home page includes an activity log (click show log) that records instance launches, connection attempts, and errors. Notifications about closed instances (for example, expired sign-in or license loss) appear at the top of the page.

Valid Windows

The Webserver is not capable of displaying all of FlexSim's different windows. If a window is not supported, it will still be displayed in the windowing interface, but no data will be available.

3D View

You can control your model in the browser using the controls at the top. You can also interact with open 3D views in your model. Left click to pan, right click to rotate, and either right-and-left click or use the mouse wheel to zoom. Additional buttons for panning, rotating, and zooming are generated for tablet devices and smartphones.

Streaming Modes

The 3D view can be configured to stream using one of two methods.

  1. Video Streaming. In this streaming mode, the 3D view is rendered on the server and the view is streamed as compressed video images to the client. This mode requires a high-end graphics configuration on the server, but minimal requirements for connected client devices.

  2. WebGL Streaming. In this streaming mode, the objects in the scene are streamed as data to the client. The 3D view is then rendered on the client device using WebGL. This mode does not require a high-end graphics configuration on the server, and it should work better with virtual machines and other server configurations that do not support hardware graphics acceleration. This mode requires using client devices and modern web browsers that support WebGL.

Starting in FlexSim 2020 Update 2, the default mode is to use WebGL Streaming. You can change this setting individually for each model on the server. To use video streaming, add a streammode node with a value of 0 to your model tree in MODEL:/Tools/serverinterface/streammode.

Dashboards

Dashboards are also displayed in real time. You can even reposition and resize dashboard statistic widgets. If the model's dashboards contain input widgets like text fields, tables, buttons, etc. you will be able to interact with these elements.

Experimenter / Optimizer

If your model has an Experimenter, a standard interface is generated for running experiments. Use the tabs at the top of the window to move between the Model Control, Experimenter and Optimizer. You can define experiment variables, run times, optimization values and other parameters.

Tablets and Smartphones

To connect other devices such as tablets and smartphones to this server, the address 127.0.0.1 will not work. The other device will need to be connected to the same local area network or wireless local area network as your computer. You will need to find the IP address of your computer. To do this, click the start button and type cmd.exe, which will open a black command prompt. Enter ipconfig and press enter. Your IPv4 Address should be entered as the URL in the browser on the device, including the configured port (for example, http://192.168.1.10:8080/).

Internet Accessibility

To use the server on the internet, your computer needs to be assigned a global IP address. Contact your network administrator.

Developing Custom Web Interfaces

The FlexSim Webserver allows you to start a simple test webserver without installing any webserver software like Apache or IIS. If you want to deploy a webserver using IIS, see Using FlexSim Webserver with IIS. You can create custom webserver applications using queries provided by FlexSim or user defined queries contained in the model. To get exact details on what a query returns, enter the query in the URL bar of the browser to view the reply (for example: 127.0.0.1:8080/webserver.dll?availablemodels).

Authentication

All webserver.dll requests require an authenticated identity when per-user licensing is enabled. In login mode, the user must have a valid APS sign-in session (browser requests are redirected to /auth/login; API callers receive HTTP 401). In network mode, the browser must hold a session cookie so the server can assign a fingerprint; instances and jobs are isolated to that session. Custom clients and forms must account for this when calling the queries below.

The following queries are available. You can also enter 127.0.0.1:8080/webserver.dll into the URL bar to display this list.

General

Instances

Libraries

Modules

Jobs

            <form action="http://127.0.0.1:8080/webserver.dll?submitjob" method="POST">
                <input type="hidden" name="job" value='{"modelname":"my%20model","timeout":3600,"priority":5,"setupcommands":
                    [{"command":"settable=modelparameters","data":"values=[[\"firstParam\",0],[\"secondParam\",2],[\"thirdParam\",\"hello\"]]"},
                    {"command":"setrunspeed=100000000"},{"command":"setstoptime=86400"},{"command":"toolsnodefunction=setupscript"},{"command":"run"}],
                    "resultcommands":[{"command":"getnodedata=/Tools/TrackedVariables/WorkInProgress"},{"command":"getnodedata=/Tools/modeloutput"}]}'>
                <input type="submit">
            </form>

The JSON object must have a "modelname" field, which is the name of the model on the server. It can have a "timeout" field, which is the maximum number of seconds to wait for the model run to complete. It must have a "setupcommands" field, which is an array of command objects. It must have a "resultcommands" field, which is an array of command objects. Command objects must have a "command" field, which is the part of a queryinstance query after webserver.dll?queryinstance=my%20model&instancenum=1&id=1&... Command objects can also have a "data" field, which is the body of the HTTP request, typically containing data from POST requests. Command objects can also have a "verb" field, which is usually "GET" or "POST".

The job will be done as soon as the server is able to make more instances of FlexSim. A createinstance query will be created under the submitting user's identity, followed by a queryinstance=my%20model&instancenum=1&defaultpage query, whose replies are ignored. The replies to each of the setup commands are then stored, followed by polling the model with queries like queryinstance=my%20model&instancenum=1&id=1&getrunstate. When the runstate is 0 (when the model is finished running), the replies to the result commands will be stored. A complete summary of the run in JSON format can be sent as a reply to a getjobresults query.

Instance Queries

Once an instance has been created, the webserver can communicate with FlexSim through query handlers. These allow you to both send and receive data from FlexSim. Query requests to the server are handled as seen in this picture:

A list of default queries is available at MAIN:/project/exec/globals/serverinterface/queryhandlers. Using these as templates you can create your own custom query handlers by adding subnodes to the MODEL:/Tools/serverinterface/queryhandlers node. These queryhandler nodes should be toggled flexscript. The name of the node corresponds to a value passed in by the query. For example, webserver.dll?queryinstance=Test%20Model&instancenum=1&reset executes the queryhandler located at MAIN:/project/exec/globals/serverinterface/queryhandlers/reset. Parameters may be added to the query to pass additional information. For example, webserver.dll?queryinstance=Test%20Model&instancenum=1&customquery=1&count=5.

When starting instances via createinstance, the reply may include a reason on failure. Common values include not signed in, license denied, registration failed, and server flexsim instance limit reached.

Custom functionality and custom query types for querying the model can also be written for a model by making a flexscript node at MODEL:/Tools/serverinterface/sendreply. This node must call webcommand("httpsendreply", replynode); once to send a reply to the query. This will send a reply in different forms, depending on the type of data in the node given as a parameter. If the node has string data containing a syntactically correct HTTP reply with HTTP headers as defined by http://www.w3.org/Protocols/rfc2616/rfc2616-sec6.html, then it will be sent as-is, giving developers full access to send any type of HTTP reply desired. Refer to the code in MAIN:/project/exec/globals/serverinterface/sendreply for an example, which can be copied and edited as needed. Remember that the defaultPage and getRunState queries are used by the job interface.

Default Page

The default web page for a model is generated by using a template found in the tree at MAIN:/project/exec/globals/serverinterface/pagetemplates/default. This is a page that is generated using FlexSim's FlexScript HTML Preprocessor (FHP), which is inspired by PHP's mentality. It is standard html code, but you can escape from the html with a ** tag.

You can also override the default html page by putting the html into a node created at MODEL:/Tools/serverinterface/defaultpagetemplate. This will override the default page of the model.

You can also generate any named html page in your model. Adding web pages using the Toolbox will put named nodes into MODEL:/Tools/serverinterface/pagetemplates with their corresponding FHP code. Then the server will serve up these pages when they are part of the HTTP request URL. For example, to make a page named "custom", add a node at MODEL:/Tools/serverinterface/pagetemplates/custom, and give it the desired FHP code. Then you can access that page by including "custom" in the page address, like the following:

http://localhost:8080/webserver.dll?queryinstance=MyModel&instancenum=1&custom

Using FlexSim Webserver with IIS

If IIS is configured to use the iisnode module, it can also manage instances of FlexSim and interact with FlexSim's webserver interface. This requires IIS 7.x with IIS Management Tools, ASP.NET, and the URL Rewrite module for IIS.

All interaction should be the same except for two major differences: visibility and threading.

  1. IIS is run in the background, so FlexSim instances will not be visible on the server. This makes it harder to debug any problems.

  2. IIS uses multiple threads to respond to requests in parallel, so the order of replying to requests could be different.

WebSockets

The FlexSim Webserver uses websockets for faster video streaming. WebSocket functionality requires IIS 8.x.

Allocating Windows Memory

There is a Windows Registry setting that limits the amount of memory (desktop heap size) that Windows will allocate for non-interactive processes. The registry path is:

        HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\SubSystems\Windows

This key has a value that is a long string with more key/value pairs:

        %SystemRoot%\system32\csrss.exe
        ObjectDirectory=\Windows
        SharedSection=1024,20480,512
        Windows=On
        SubSystemType=Windows
        ServerDll=basesrv,1
        ServerDll=winsrv:UserServerDllInitialization,3
        ServerDll=sxssrv,4
        ProfileControl=Off
        MaxRequestThreads=16

The SharedSection key defines, in its 3rd parameter, the amount of memory that can be allocated by IIS. By default, this is 512. If you need to open multiple instances of FlexSim through the webserver, you may need to increase this number to beyond the total amount of memory that all your instances will use simultaneously. This number will vary based upon the memory requirements of the models that are being run.

Be sure to reboot your machine after making any changes.

Configuring IIS

IIS requires some additional configuration to work with FlexSim. The steps are outlined as follows:

Windows Server operating systems and 64 bit operating systems may have some additional complications.

Windows Authentication in IIS

Under Sites/Default Web Site, double click on Authentication. Enable Windows Authentication.

Using FlexSim Webserver with NGINX Reverse Proxy

nginx.conf must be configured properly to use the FlexSim Webserver with NGINX. In the following example all requests for 127.0.0.1/model/ are forwarded to 127.0.0.1:8080/. This assumes the FlexSim Webserver is running and bound to port 8080. HTTP upgrade headers are also forwarded to enable WebSockets.

When using login licensing mode, also proxy the /auth/ paths and set Licensing.Redirect URI to the public callback URL (for example, https://yourserver.example.com/auth/callback).

        location /model/ {
            rewrite ^ $request_uri;
            rewrite ^/model(/.*) $1 break;
            return 400;
            proxy_pass http://127.0.0.1:8080$uri;

            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
        }