[Mono-list] Remoting status
Lluis Sanchez
lluis@ideary.com
Mon, 27 Jan 2003 21:35:52 +0100
This is a multi-part message in MIME format.
------=_NextPart_000_00B3_01C2C64C.11197390
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
Hello!
For those who are interested in Remoting, here is a summary of the current
status:
* The basic Remoting infrastructure (channels, sinks and all this) is not
finished, but it is complete enough for testing. Since RemotingConfiguration
is not yet finished, use RemotingServices.Marshal to publish an object, and
Activator.GetObject() to get an object form a server.
* The TcpChannel is working, but it is currently not compatible with MS' tcp
channel.
* BinaryFormatterProvider is also working. All formatting is done by
BinaryFormatter, which is quite complete. It can serialize complex
parameters and return values, including arrays, enums and delegates.
* Marshalling and unmarshalling of MarshalByRefObject instances is working,
so you can pass object references between applications. Delegates are not
working with MBR objects due to a problem with virtual methods and
transparent proxy. I think Patrik is working to solve this (and many other
things!)
I've prepared simple an example of a client application that connects to an
object in a server application and calls some methods. I think it is the
better way to show you what can remoting do and how to do it. To test it,
compile like this:
mcs -t:library ServerObject.cs
mcs -r:ServerObject.dll -r:System.Runtime.Remoting.dll RemotingClient.cs
mcs -r:ServerObject.dll -r:System.Runtime.Remoting.dll RemotingServer.cs
Enjoy !
Lluis.
------=_NextPart_000_00B3_01C2C64C.11197390
Content-Type: text/plain;
name="RemotingClient.cs"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
filename="RemotingClient.cs"
using System;
using System.Net;=0A=
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
namespace RemotingTest
{=0A=
class RemotingClient=20
{
static void Main ()=20
{
TcpChannel ch =3D new TcpChannel(0);
ChannelServices.RegisterChannel (ch);
// This gets the object from the server (a list of ServerObject)
Console.WriteLine("Getting instance ...");
object remOb =3D =
Activator.GetObject(typeof(ServerList),"tcp://localhost:1122/test.rem");
=09
ServerList list =3D (ServerList)remOb;
// These are remote calls that return references to remote objects
Console.WriteLine ("Creating two remote items...");
ServerObject item1 =3D list.NewItem ("Created at server 1");
item1.SetValue (111); // another call made to the remote object
ServerObject item2 =3D list.NewItem ("Created at server 2");
item2.SetValue (222);
Console.WriteLine ();
// Two objects created in this client app
Console.WriteLine ("Creating two client items...");
ServerObject item3 =3D new ServerObject ("Created at client 1");
item3.SetValue (333);
ServerObject item4 =3D new ServerObject ("Created at client 2");
item4.SetValue (444);
Console.WriteLine ();
// Object references passed to the remote list
Console.WriteLine ("Adding items...");
list.Add (item3);
list.Add (item4);
Console.WriteLine ();
// This sums all values of the ServerObjects in the list. The server
// makes a remote call to this client to get the value of the
// objects created locally
Console.WriteLine ("Processing items...");
list.ProcessItems ();
Console.WriteLine ();
// Passing some complex info as parameter and return value
Console.WriteLine ("Setting complex data...");
ComplexData cd =3D new ComplexData (AnEnum.d, new object[] =
{"some",22,"info"});
ComplexData res =3D list.SetComplexData (cd);
Console.WriteLine ("This is the result:");
res.Dump();
Console.WriteLine ();
list.Clear();
Console.WriteLine ("Done.");
ch.StopListening (null);
}
}
}
------=_NextPart_000_00B3_01C2C64C.11197390
Content-Type: text/plain;
name="RemotingServer.cs"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
filename="RemotingServer.cs"
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
namespace RemotingTest
{=0A=
class RemotingServer
{
static int Main ()=20
{
Console.WriteLine("Starting Server");
TcpChannel ch =3D new TcpChannel(1122);
ChannelServices.RegisterChannel (ch);
ServerList ser =3D new ServerList();
RemotingServices.Marshal(ser,"test.rem");
Console.WriteLine("Server Running ...");
Console.ReadLine();
ch.StopListening (null);
return 0;
}
}
}
------=_NextPart_000_00B3_01C2C64C.11197390
Content-Type: text/plain;
name="ServerObject.cs"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
filename="ServerObject.cs"
using System;
using System.Runtime.Remoting;
using System.Collections;
namespace RemotingTest
{=0A=
// A list of ServerObject instances=0A=
=0A=
public class ServerList: MarshalByRefObject
{
ArrayList values =3D new ArrayList();
public void Add (ServerObject v)
{
values.Add (v);
System.Console.WriteLine ("Added " + v.Name);
}
public void ProcessItems ()
{
System.Console.WriteLine ("Processing...");
int total =3D 0;
foreach (ServerObject ob in values)
total +=3D ob.GetValue();
System.Console.WriteLine ("Total: " + total);
}
public void Clear()
{
values.Clear();
}
=09
public ServerObject NewItem(string name)
{
ServerObject obj =3D new ServerObject(name);
Add (obj);
return obj;
}
public ComplexData SetComplexData (ComplexData data)
{
System.Console.WriteLine ("Showing content of ComplexData");
data.Dump ();
return data;
}
}
=09
// A remotable object
public class ServerObject: MarshalByRefObject
{
int _value;
string _name;
public ServerObject (string name)
{
_name =3D name;
}
public string Name
{
get { return _name; }
}
public void SetValue (int v)
{
System.Console.WriteLine ("ServerObject " + _name + ": setting " + =
v);
_value =3D v;
}
public int GetValue ()
{
System.Console.WriteLine ("ServerObject " + _name + ": getting " + =
_value);
return _value;
}
}
// Some complex data for testing serialization
public enum AnEnum { a,b,c,d,e };
[Serializable]
public class ComplexData
{
public AnEnum Val =3D AnEnum.a;
public object[] Info;
public ComplexData (AnEnum va, object[] info)
{
Info =3D info;
Val =3D va;
}
public void Dump ()
{
System.Console.WriteLine ("Content:");
System.Console.WriteLine ("Val: " + Val);
foreach (object ob in Info)
System.Console.WriteLine ("Array item: " + ob);
}
}
}
------=_NextPart_000_00B3_01C2C64C.11197390--