Navigation:  Communication Libary > Supported Servers >

WebORB for .NET

Previous pageReturn to chapter overviewNext page

WebORB for .NET is an RTMP server implemented natively in .NET. Any custom server-side functionality can be implemented in any CLR language and target versions of the .NET framework starting at 2.0 and above. When WebORB is hosted in IIS, the RTMP server is started from the Global.asax file with a very first request to the virtual directory. Additionally, the WebORB RTMP server can run standalone both as a service or a console application by running the weborbee.exe executable located in the root of the installation directory. WebORB for .NET uses the port 2037 for all RTMP connections.

Creating an RTMP application

A WebORB for .NET messaging application can be set up by creating a directory under the [WEBORB-HOME-DIR]/Applications/. Once a directory is created, make sure the WebORB server is restarted so it recognizes the application. When connecting to the server, the name of the folder is the name of the application in the connect call.

Custom Server-Side Code

A WebORB RTMP application can be extended with custom code containing the application logic. The code must be a .NET class inheriting from Weborb.Messaging.Server.Adapter.ApplicationAdapter. Any public method added to the class can be invoked by the connected clients. To deploy the custom code, compile it as a .NET class library and copy the assembly into the /bin folder of the application where WebORB is deployed (or the /bin folder of the default WebORB installation). The RTMP application must also contain a configuration file in its folder. The configuration file associates the application handler class with the application. See the WebORB Documentation for additional details.

Data Push (server-to-client calls)

WebORB for .NET supports server to client invocation via the IServiceCapableConnection interface.The interface represents a connection between an RTMP client the current application. The code snippet shown below demonstrates how to invoke a method on all client connections when a client disconnects. Specifically, the code invokes the client-side "clientDisconnected" method with one argument - client's ID.

using System;
using System.Collections.Generic;
using System.Text;
 
using Weborb.Messaging.Api;
using Weborb.Messaging.Api.Service;
using Weborb.Messaging.Server.Adapter;
 
namespace Example
{
 public class AppHandler : ApplicationAdapter
 {
   public override void appDisconnect( IConnection conn )
   {
     IEnumerator<IConnection> connections = scope.getConnections();
 
     while( connections.MoveNext() )
     {
       IConnection connection = connections.Current;
       Object[] args = new Object[] { conn.getClient().getId() };
 
       if( connection is IServiceCapableConnection )
        ((IServiceCapableConnection)connection).invoke( "clientDisconnected", args );
     }
   }
 }
}

Remote Shared Objects

WebORB's server-side remote shared objects provide support for the following use-cases:

Obtaining a reference to a remote shared object
Adding shared object listener to receive notifications for updates, deletes and sent messages
Updating shared object property
Clearing/deleting all shared object properties
Sending a message to all shared object clients

 

Obtaining ISharedObject Reference

To obtain a reference to a remote shared object, use the getSharedObject method in the ApplicationAdapter subclass. The method returns an instance of the Weborb.Messaging.Api.SO.ISharedObject interface. The object is a server-side representation of the shared object, it provides access to all the RSO functionality, including setting RSO properties, delivering messages to the clients, etc:

using System;
 
using Weborb.Messaging.Api;
using Weborb.Messaging.Api.SO;
using Weborb.Messaging.Server.Adapter;
 
namespace Examples
{
 public class AppHandler : ApplicationAdapter
 {
   private ISharedObject myRSO;
 
   public override bool  appStart(IScope app)
   {
     bool appStarted = base.appStart( app );
 
     if( appStarted )
       myRSO = getSharedObject( app, "ChatSO", true );
         
     return appStarted;
   }
 }
}

 

Adding Listener

In order to receive notifications about RSO property updates, as well as many other RSO-related events, a listener should be added to a remote shared object reference. RSO listeners must implement the Weborb.Messaging.Api.SO.ISharedObjectListener interface. A listener can be added to an instance of ISharedObject using the addSharedObjectListener method:

using System;
 
using Weborb.Messaging.Api;
using Weborb.Messaging.Api.SO;
using Weborb.Messaging.Server.Adapter;
 
namespace Examples
{
 public class AppHandler : ApplicationAdapter
 {
   private ISharedObject myRSO;
 
   public override bool  appStart(IScope app)
   {
     bool appStarted = base.appStart( app );
 
     if( appStarted )
     {
      myRSO = getSharedObject( app, "ChatSO", true );
      myRSO.addSharedObjectListener( new MyRSOListener() );
     }
   
     return appStarted;
   }
 }
 
 public class MyRSOListener : ISharedObjectListener
 {
   public void onSharedObjectConnect( ISharedObjectBase so )
     {
      // a client has connected to the shared object
     }
 
   public void onSharedObjectDisconnect( ISharedObjectBase so )
     {
      // a client has disconnected from the shared object
     }
 
   public void onSharedObjectUpdate( ISharedObjectBase so, string key, object value )
     {
      // a shared object property with the 'key' has been updated. The value is 'value'
     }
 
   public void onSharedObjectUpdate( ISharedObjectBase so, IAttributeStore values )
     {
      // shared object properties have been updated. The updated key/value pairs are in 'values'
     }
 
   public void onSharedObjectUpdate( ISharedObjectBase so, IDictionary<string, object> values )
     {
      // shared object properties have been updated. The updated key/value pairs are in 'values'
     }
 
   public void onSharedObjectDelete( ISharedObjectBase so, string key )
     {
      // a shared object property with the key 'key' has been removed
     }
 
   public void onSharedObjectClear( ISharedObjectBase so )
     {
      // all shared object properties have been cleared
     }
 
   public void onSharedObjectSend( ISharedObjectBase so, string method, IList parms )
     {
       // a client sent a message 'method' with parameters 'parms' to all the clients of the shared object identified by so
     }
  }
}

Updating Property

When a shared object property is updated, WebORB delivers a notification event to all clients connected to the shared object. To update a property, use the setAttribute method on the RSO reference. Consider the following example:

Hashtable messageObject = new Hashtable();
messageObject[ "imText" ] = messageText;
messageObject[ "username" ] = ".NET Client";
messageObject[ "color" ] = 0;
messageObject[ "isBold" ] = false;
messageObject[ "isItalics" ] = false;
messageObject[ "isUnderline" ] = false;
myRSO.setAttribute( "UserMessage", messageObject );

The code above updates the "UserMessage" property of a remote shared object with an untyped object (represented as Hashtable). Alternatively, the code could be rewritten to use a strongly typed object:

InstantMessage messageObject = new InstantMessage();
messageObject.imText = messageText;
messageObject.username = ".NET Client";
messageObject.color = 0;
messageObject.isBold = false;
messageObject.isItalics = false;
messageObject.isUnderline = false;
myRSO.setAttribute( "UserMessage", messageObject );
 
public class InstantMessage
{
 public String imText {get; set;}
 public String userName {get; set;}
 public int color {get; set;}
 public bool isBold {get; set;}
 public bool isItalics {get; set;}
 public bool isUnderline {get; set;}
}

 

Deleting All Shared Object Properties

To delete all shared object properties use the clear method on the ISharedObject reference. See Obtaining ISharedObject Reference for details. When the method is invoked, WebORB notifies all other connected clients that the properties have been deleted.

 

Sending Messages To All RSO Clients

To delete all shared object properties use the sendMessage method on the ISharedObject reference. See Obtaining ISharedObject Reference for details. When the method is called, WebORB sends a notification event to invoke the method with the specified arguments on all clients connected to the remote shared object. See Server Data Push for additional details.