Share via


Setting Server Limits

banner art

Previous Next

Setting Server Limits

To keep resource usage, including bandwidth and memory, at manageable levels, you must set some server limits. You can use the IWMSServerLimits object to specify and retrieve these settings.

The following examples illustrate how to control resource usage on a Windows Media Server by setting various server limit values.

Visual Basic .NET Example

Imports Microsoft.WindowsMediaServices.Interop
Imports System.Runtime.InteropServices

' Declare variables.
Dim Server As WMSServer
Dim Limits As IWMSServerLimits

Try
    ' Create the WMSServer object and retrieve 
    ' IWMSServerLimits object.
    Server = New WMSServer()
    Limits = Server.Limits

    ' Set the maximum number of connected clients.
    Limits.ConnectedPlayers = 10

    ' Set the maximum CPU usage allowed during a
    ' client connection.
    Limits.CPUUtilizationDuringConnection = 80

    ' Set the maximum bandwidth usage for each client.
    Limits.PerPlayerConnectionBandwidth = 128

    ' Set the maximum time a client can remain inactive
    ' before being disconnected.
    Limits.PlayerInactivityTimeout = 4000

Catch errCom As COMException
    ' TODO: Handle COM exceptions.
Catch err As Exception
    ' TODO: Exception handler goes here.
Finally
    ' TODO: Clean-up code goes here.
End Try

C# Example

using Microsoft.WindowsMediaServices.Interop;
using System.Runtime.InteropServices;

WMSServer Server;
IWMSServerLimits Limits;

try
{
    // Create the WMSServer object and retrieve 
    // IWMSServerLimits object.
    Server = new WMSServerClass();
    Limits = Server.Limits;

    // Set the maximum number of connected clients.
    Limits.ConnectedPlayers = 10;

    // Set the maximum CPU usage allowed during a
    // client connection.
    Limits.CPUUtilizationDuringConnection = 80;

    // Set the maximum bandwidth usage for each client.
    Limits.PerPlayerConnectionBandwidth = 128;

    // Set the maximum time a client can remain inactive
    // before being disconnected.
    Limits.PlayerInactivityTimeout = 4000;
}
catch (COMException comExc)
{
    // TODO: Handle COM exceptions.
}
catch (Exception exc)
{
    // TODO: Exception handler goes here.
}
finally
{
    // TODO: Clean-up code goes here.
}

C++ Example

#include <windows.h>
#include "wmsserver.h"

// Declare variables and interfaces.
IWMSServer       *pServer;
IWMSServerLimits *pLimits;

HRESULT          hr;

// Initialize the COM library and retrieve a pointer
// to an IWMSServer interface.
hr = CoInitialize(NULL);
hr = CoCreateInstance(CLSID_WMSServer,
                      NULL,
                      CLSCTX_ALL,
                      IID_IWMSServer,
                      (void **)&pServer);
if (FAILED(hr)) goto EXIT;

// Retrieve a pointer to the IWMSServerLimits interface.
hr = pServer->get_Limits(&pLimits);
if (FAILED(hr)) goto EXIT;

// Set the maximum number of connected clients.
hr = pLimits->put_ConnectedPlayers(10);
if (FAILED(hr)) goto EXIT;

// Set the maximum CPU usage allowed during a
// client connection.
hr = pLimits->put_CPUUtilizationDuringConnection(80);
if (FAILED(hr)) goto EXIT;

// Set the maximum bandwidth usage for each client.
hr = pLimits->put_PerPlayerConnectionBandwidth(128);
if (FAILED(hr)) goto EXIT;

// Set the maximum time a client can remain inactive
// before being disconnected.
hr = pLimits->put_PlayerInactivityTimeout(4000);
if (FAILED(hr)) goto EXIT;

EXIT:
    // TODO: Release temporary COM objects and uninitialize COM.

See Also

Previous Next