[Mono-list] remoting mono with MS' CLR?

Joe Castro t-joec@microsoft.com
Sun, 29 Jun 2003 19:51:44 -0700


Hi Lluis, thanks for responding.  Sorry for the delayed writeback, I
haven't been able to get into my school account.
Below is posted the exact code I'm using in attempt to get this to work,
removing the hardcoded IP addresses I've been using for the server.
Please forgive the length, I wouldn't ask you to parse through my code
but I'm not sure how much more academic I can make the case except for
the WriteLines. There are four files, Client, Server, Remotable, and
ToPass.  I've played around with a few variations but to no avail :(
Fine on localhost, fine between Windows, problems with Windows to Linux.
Thanks for any help with this.
    -Joe

//Client.cs
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;

namespace Joe.Remoting {
    public class Client {
        public static void Main() {
             Console.WriteLine( "Starting the Client . . ." );
             try {
                 Console.WriteLine( "\tAttempting to open TcpChannel");
                 ChannelServices.RegisterChannel( new TcpChannel() );
                 Console.WriteLine( "\tAttempting to get remote object"
);
                 Remotable rref =3D (Remotable)Activator.GetObject(
                     typeof(Remotable),
                     "tcp://xxx.xxx.xxx.xxx:8011/RemoteTesting" );
                 if( (object)rref =3D=3D null )
                     throw new Exception( "Couldn't grab remote
reference" );
                 else Console.WriteLine("\tGot reference, attempting to
assign to it");
                 //The above doesn't actually check that the object is
valid, it throws
                 //an exception when I try to access it, stating that
"Connection
                 //refused if server's not open.  This is even how MSDN
documents
                 //how to do this, is there a better way to do this?
                 rref.Doer =3D new ToPass();
                 Console.WriteLine( "\tAttempting to make a remote call"
);
                 string ret =3D rref.ProxyDo("this","is","a","test");
                 if( ret =3D=3D null )
                     throw new Exception("IDoer.DoesSomething didn't
work");
                 Console.WriteLine( "\tRemote call returned:\n\t\t{0}",
ret );
             } catch( Exception e ) {
                 Console.WriteLine( "An exception occured:\n{0}", e );
             }
             Console.WriteLine( "Finished running the Client." );
        }
    }  =20
}

//Server.cs
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;

namespace Joe.Remoting {
    public class JoeServer {
        private const int Port =3D 8011;
        public static void Main() {
            Console.WriteLine( "Starting the Server . . ." );
            Console.WriteLine( "\tAttempting to create TCP channel" );
            try {
                ChannelServices.RegisterChannel( new TcpChannel(Port) );
                RemotingConfiguration.RegisterWellKnownServiceType(
                    new Remotable().GetType(),
                    //Type.GetType("Joe.Remoting.Remotable"),//Doesn't
work?
                    "RemoteTesting",
                    WellKnownObjectMode.Singleton );
                Console.WriteLine("\tServer is now listening on port
{0}",Port);
            } catch( Exception e ) {
                Console.WriteLine( "An error has occured:\n\n{0}", e );
            }
            Console.WriteLine( "Press enter to quit" );
            Console.ReadLine();
        }
    }
}

//Remotable.cs
using System;
namespace Joe.Remoting {
    public interface IDoer {
        string DoesSomething( params object[] oary );
    }
    [Serializable]
    public class Remotable : MarshalByRefObject {
        private IDoer todo;
        public Remotable()
            : this( null )
        {}
        public Remotable( IDoer todo ){
            this.todo =3D todo;
        }
        public IDoer Doer {
            get { return todo; }
            set { todo =3D value; }
        }
        public string ProxyDo( params object[] oary ){
            return todo.DoesSomething( oary );
        }
    }
}
//ToPass.cs
using System;

namespace Joe.Remoting {
    [Serializable]
    public class ToPass : IDoer {
        public string DoesSomething( params object[] oary ){
            foreach( object o in oary )
                Console.WriteLine( o );
            return "There were " + oary.Length + " elements passed.";
        }
    }
}

-----Original Message-----
From: Lluis Sanchez [mailto:lluis@ideary.com]=20
Sent: Thursday, June 26, 2003 10:39 AM
To: mono-list@lists.ximian.com; joe@cs.ucsb.edu
Subject: Re: [Mono-list] remoting mono with MS' CLR?

Hi,

> Hi, I was wondering if anyone had any experience using remoting
through a
> TCP connection between Mono and Microsoft's implementation of the CLR?
I
> have a sample program that works on mono when remoting to the local
host
as
> well as when remoting between two windows machines, but between linux
and
> windows it crashes, regardless of which is the server or client.  This
is
> without using cygwin, which I can't use for this for various reasons.
Is
> this supposed to be working at this point in Mono's development?  I
just
> want to know if the error is on my end or should I try to find another
route
> to try with this project.
> Much thanks in advance for any help on this.
> -Joe

The TcpChannel and the BinaryFormatter is (or should be) compatible with
MS.NET. However, some classes from the library may have a different
binary
representation, because they may have a different internal data
structure,
so for example you won't be able to exchange a Hastable object between
Mono
and MS.NET. It should not be a problem if you are using primitive types,
arrays or your own classes. In any case, could you post a test case?

- Lluis.

>
> _______________________________________________
> Mono-list maillist  -  Mono-list@lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-list
>