|
A messaging application on the
server-side must be represented through a directory
under the /Applications folder. The directory may
contain application configuration. Additionally,
WebORB stores application instances (rooms) , shared
objects and streams.
Application custom logic must reside
in the application handler class. The class must
implement the Weborb.Messaging.Api.IScopeHandler
interface or can extend the
Weborb.Messaging.Server.Adapter.ApplicationAdapter
class (recommended).
Application handler receives the
following callbacks from the WebORB server:
|
public virtual
bool appStart( IScope
app );
public virtual bool
appStop( IScope app );
public virtual bool
roomStart( IScope room );
public virtual void
roomStop( IScope room );
public virtual bool
appConnect( IConnection conn, Object[] parms );
public virtual bool
roomConnect( IConnection conn, Object[] parms );
public virtual void appDisconnect(
IConnection conn );
public virtual void
roomDisconnect( IConnection conn );
public virtual bool
appJoin( IClient client, IScope app );
public virtual void
appLeave( IClient client, IScope app );
public virtual bool
roomJoin( IClient client, IScope room );
public virtual void
roomLeave( IClient client, IScope room );
|
Suppose your application needs to
notify other connected clients when a new client
joins or leaves the application. The notification
can be done as an invocation of the client side
ActionScript function. The code below demonstrates
the API:
|
using System;
using System.Collections.Generic;
using System.Text;
using Weborb.Messaging.Api;
using Weborb.Messaging.Api.Service;
using Weborb.Messaging.Server.Adapter;
namespace Weborb.Examples.ClientCallback
{
public class
AppHandler : ApplicationAdapter
{
public override bool appConnect(
IConnection conn, object[]
parms )
{
// get the connections for
the scope (scope comes from the base class)
IEnumerator<IConnection>
connections = scope.getConnections();
Object[] args =
new Object[] {
conn.getClient().getId() };
// iterate over the connections
while(
connections.MoveNext() )
{
IConnection
connection = connections.Current;
// invoke
client side function via the client connection
if(
connection is
IServiceCapableConnection )
((IServiceCapableConnection)connection).invoke(
"clientConnected",
args );
}
//notify client about his
ID
if( conn
is IServiceCapableConnection
)
((IServiceCapableConnection)conn).invoke(
"setClientID", args );
return true;
}
public override void
appDisconnect( IConnection conn )
{
IEnumerator<IConnection>
connections = scope.getConnections();
Object[] args =
new Object[] {
conn.getClient().getId() };
while(
connections.MoveNext() )
{
IConnection
connection = connections.Current;
if( connection
is IServiceCapableConnection
)
((IServiceCapableConnection)connection).invoke(
"clientDisonnected",
args );
}
}
}
}
|
Download full source code listing
here.
Compile the application handler
class and place it into the WebORB's /bin folder. If
WebORB runs inside of IIS, the /bin folder is the
same where all class libraries for the given ASP.NET
application are deployed. If WebORB runs standalone,
the /bin folder is where weborb.dll resides.
Create "CallbackDemo" folder under
/Applications. The name of the folder will be used
in the client code to connect to the application.
Place app.config into /Applications/CallbackDemo.
The file must contain the following contents:
|
<?xml
version="1.0" encoding="utf-8"?>
<configuration>
<application-handler>
Weborb.Examples.ClientCallback.AppHandler
</application-handler>
</configuration>
|
The server side of the application
is ready.
|