Groups | Blog | Home
all groups > dotnet remoting > may 2004 >

dotnet remoting : Initializing SAO


Emiel van de Laar
5/27/2004 12:18:34 PM
Greetings,

I'm building a small sample application in order to better understand
..NET remoting. I have a graph object (my model) which lives on the
server side as a Singleton activated object. Clients can access this
object and, for example, add or remove a node.

When a client connects a new graph object is instatiated and on every
consecutive client connection (i.e. new Graph()) the reference to the
existing graph object is returned. Thus in order to "have" a graph
object a single client must have connected.

My question is if there is anyway to initialize the graph object on the
server side and then obtain a remote object reference to the existing
object on the client side? I have attempted this already but when the
clients call "new Graph()" a new remote graph object is created instead.

The code...

<server>
namespace Server
{
class App
{

Graph graph;

public App()
{
RemotingConfiguration.Configure("Server.exe.config");

// I want a client reference to this existing object
graph = new Graph();
graph.AddVertex("foo", 1, 2);

Console.WriteLine("Press enter to exit...");
Console.ReadLine();
}

static void Main(string[] args)
{
new App();
}
}
}
</server>

<server config>

<configuration>
<system.runtime.remoting>
<application name="Server">

<service>
<wellknown mode="Singleton"
type="Model.Graph, Graph"
objectUri="Graph" />
</service>

<channels>
<channel ref="tcp" port="2600" />
</channels>

</application>
</system.runtime.remoting>
</configuration>

</server config>

<client>
....
RemotingConfiguration.Configure("Client.exe.config");
Graph = new Graph();
....
</client>

<client config>

<configuration>
<system.runtime.remoting>
<application name="Client">

<client>
<wellknown
type="Model.Graph, Graph"
url="tcp://localhost:2600/Graph" />
</client>

<channels>
<channel ref="tcp" />
</channels>

</application>
</system.runtime.remoting>
</configuration>

</client config>

Thanks in advance.

Cheers,

Emiel
--
Sunny
5/27/2004 12:25:48 PM
Hi Emiel,

to do this remove the <service> part from your server config file, and
look inline for changes in your code:

[quoted text, click to view]

RemotingServices.Marshal(graph, "Graph");
[quoted text, click to view]

-- remove from here

[quoted text, click to view]

-- to here

[quoted text, click to view]


Hope that helps
juergen doubrawa
5/27/2004 4:31:29 PM
Hi,

I think you are looking for this:

namespace Server
{
class App
{

Graph graph;

public App()
{
graph = new Graph();
graph.AddVertex("foo", 1, 2);

// do this instead of RemotingConfiguration.Configure()
TcpChannel chan = new TcpChannel(2600);
ChannelServices.RegisterChannel(chan);
RemotingServices.Marshal((Model.Graph) graph, "Graph");

Console.WriteLine("Press enter to exit...");
Console.ReadLine();
}

static void Main(string[] args)
{
new App();
}
}
}

Emiel van de Laar
5/27/2004 5:43:28 PM
Juergen,

[quoted text, click to view]

[snip]

[quoted text, click to view]

[snip]

Perfect. :) Thank you very much.

Cheers,

Emiel
--
AddThis Social Bookmark Button