[Mono-list] Remoting

Wilhelm Patrick Patrick.Wilhelm@khe.siemens.de
Tue, 5 Aug 2003 17:47:17 +0200


I got the Remoting System running on Linux->Linux and Windows->Windows (with
MS.NET on Windows and mono on linux), but I got errors when trying
Windows->Linux or Linux->Windows.

Here's the Programm I use for testing:

//Listener.cs
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using NRemotingType;

namespace NRemotingTestServer
{
  public class Listener
  {
    public static void GoListening()
    {
      GoListening(13100);
    }

    public static void GoListening(int port)
    {
      ChannelServices.RegisterChannel(new TcpChannel(port));
      RemotingConfiguration.ApplicationName = @"RemotingTestServer";
 
RemotingConfiguration.RegisterActivatedServiceType(typeof(RemotableType));

      Console.WriteLine("Listening for requests on port {0}. Press Enter to
exit...",port);
      Console.ReadLine();
    }
  }
}

############################################################################
#########

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


namespace NRemotingTestClient
{
  public class Client
  {

    public static void Connect()
    {
      Connect(@"localhost",13100);
    }

    public static void Connect(string serverAdress, int port)
    {
      Console.WriteLine("Connecting to server {0} at port
{1}",serverAdress,port);

      ChannelServices.RegisterChannel(new TcpChannel());
      RemotingConfiguration.ApplicationName = @"RemotingTestClient";
 
RemotingConfiguration.RegisterActivatedClientType(typeof(RemotableType),@"tc
p://" + serverAdress + @":" + port.ToString());

      RemotableType remoteObject = new RemotableType();
      remoteObject.WriteToServerConsole("Hello this text is from the
client");
    }
  }
}

############################################################################
#########

// RemotableType.cs
using System;

namespace NRemotingType
{
  public class RemotableType : MarshalByRefObject
  {
    public void WriteToServerConsole(string sText)
    {
      Console.WriteLine(sText);
    }
  }
}

############################################################################
#########

//MainClass.cs

using System;
using NRemotingTestServer;
using NRemotingTestClient;

namespace NRemotingTestApp
{
	class MainClass
	{
    enum AppMode 
    {
      Client,
      Server
    }

    static AppMode appMode;
    static string serverAdress = @"localhost";
    static int port = 13100;

		[STAThread]
		static void Main(string[] args)
		{
      // check for command line arguments
      if (ParseArgs(args))
      {
        Console.WriteLine("Using tcp channel");
        // start server or client
        Init();
      }
		}

    static bool ParseArgs(string []args) 
    {
      // set the standard appMode to server
      // (if not set with parameters)
      appMode = AppMode.Server;
      for (int i=0; i<args.GetLength(0); i++) 
      {
        switch (args[i])
        {
          case "-server":
            appMode = AppMode.Server;
            break;
          case "-client":
            appMode = AppMode.Client;
            break;
          case "-s":
            serverAdress = args[i+1];
            //skip the following server adress
            i++;
            break;
          case "-p":
            port = int.Parse(args[i+1]);
            //skip the following port number
            i++;
            break;          default:
            Console.WriteLine("Unknown argument: {0}", args[i]);
            return false;
        }
      }
      return true;
    }

      static void Init()
      {
        switch (appMode)
        {
          case AppMode.Client:
            Client.Connect(serverAdress,port);
            break;
          case AppMode.Server:
            Listener.GoListening(port);
            break;
          default:
            break;
        }
      }
	}
}

############################################################################
#########

When trying Windows-Linux I get the following error:

D:\wilhelmp\RemotingTest\bin\Debug>RemotingTest.exe -client -s 192.168.0.1
Using tcp channel
Connecting to server 192.168.0.1 at port 13100

Unhandled Exception: System.Runtime.Remoting.RemotingException: Underlying
socket was closed.

Server stack trace:
   at System.Runtime.Remoting.Channels.SocketHandler.ReadFromSocket(Byte[]
buffer, Int32 offset, Int32 count)
   at System.Runtime.Remoting.Channels.SocketHandler.BufferMoreData()
   at System.Runtime.Remoting.Channels.SocketHandler.Read(Byte[] buffer,
Int32 offset, Int32 count)
   at
System.Runtime.Remoting.Channels.SocketHandler.ReadAndMatchFourBytes(Byte[]
buffer)
   at
System.Runtime.Remoting.Channels.Tcp.TcpSocketHandler.ReadVersionAndOperatio
n(UInt16& operation)
   at
System.Runtime.Remoting.Channels.Tcp.TcpClientSocketHandler.ReadHeaders()
   at
System.Runtime.Remoting.Channels.Tcp.TcpClientTransportSink.ProcessMessage(I
Message msg, ITransportHeaders requestHeaders, Stream requestStream,
ITransportHeaders& responseHeaders, Stream& respo
nseStream)
   at
System.Runtime.Remoting.Channels.BinaryClientFormatterSink.SyncProcessMessag
e(IMessage msg)

Exception rethrown at [0]:
   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage
reqMsg, IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&
msgData, Int32 type)
   at
System.Runtime.Remoting.Activation.IActivator.Activate(IConstructionCallMess
age msg)
   at
System.Runtime.Remoting.Activation.LocalActivator.DoRemoteActivation(IConstr
uctionCallMessage ctorMsg)
   at
System.Runtime.Remoting.Activation.LocalActivator.Activate(IConstructionCall
Message ctorMsg)
   at
System.Runtime.Remoting.Activation.AppDomainLevelActivator.Activate(IConstru
ctionCallMessage ctorMsg)
   at
System.Runtime.Remoting.Messaging.ClientContextTerminatorSink.SyncProcessMes
sage(IMessage reqMsg)
   at
System.Runtime.Remoting.Activation.ActivationServices.Activate(RemotingProxy
remProxy, IConstructionCallMessage ctorMsg)
   at System.Runtime.Remoting.Proxies.RemotingProxy.Invoke(IMessage reqMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&
msgData, Int32 type)
   at NRemotingType.RemotableType..ctor()
   at NRemotingTestClient.Client.Connect(String serverAdress, Int32 port) in
d:\wilhelmp\remotingtest\client.cs:line 56
   at NRemotingTestApp.MainClass.Init() in
d:\wilhelmp\remotingtest\mainclass.cs:line 88
   at NRemotingTestApp.MainClass.Main(String[] args) in
d:\wilhelmp\remotingtest\mainclass.cs:line 47

D:\wilhelmp\RemotingTest\bin\Debug>

############################################################################
#########

When trying Linux-Windows I get the following error:

wilhelmp@LINUX-S-01:~/src/RemotingTest/bin/Debug> mono RemotingTest.exe
-client -s 192.168.0.98
Using tcp channel
Connecting to server 192.168.0.98 at port 13100

Unhandled Exception: System.Reflection.TargetInvocationException: Exception
has been thrown by the target of an invocation.in <0x000ab> 00
System.Runtime.Remoting.Proxies.RealProxy:PrivateInvoke
(System.Runtime.Remoting.Proxies.RealProxy,System.Runtime.Remoting.Messaging
.IMessage,System.Exception&,object[]&)
in (unmanaged) 07
System.Runtime.Remoting.Activation.RemoteActivator:Activate
(System.Runtime.Remoting.Activation.IConstructionCallMessage)
in <0x00004> 07 System.Runtime.Remoting.Activation.RemoteActivator:Activate
(System.Runtime.Remoting.Activation.IConstructionCallMessage)
in <0x000c1> 00
System.Runtime.Remoting.Activation.AppDomainLevelActivator:Activate
(System.Runtime.Remoting.Activation.IConstructionCallMessage)
in <0x0003f> 00
System.Runtime.Remoting.Activation.ActivationServices:RemoteActivate
(System.Runtime.Remoting.Activation.IConstructionCallMessage)


Exception rethrown at [1]:
 ---> System.Runtime.Serialization.SerializationException: No element named
RemoteStackTrace could be found.
in <0x000eb> 00 System.Runtime.Serialization.SerializationInfo:GetValue
(string,System.Type)
in <0x0001f> 00 System.Runtime.Serialization.SerializationInfo:GetString
(string)
in <0x00130> 00 System.Exception:.ctor
(System.Runtime.Serialization.SerializationInfo,System.Runtime.Serialization
.StreamingContext)
in <0x00025> 00 System.SystemException:.ctor
(System.Runtime.Serialization.SerializationInfo,System.Runtime.Serialization
.StreamingContext)
in <0x00025> 00 System.Runtime.Remoting.RemotingException:.ctor
(System.Runtime.Serialization.SerializationInfo,System.Runtime.Serialization
.StreamingContext)
in (unmanaged) /usr/lib/libmono.so.0 [0x4005168a]
in (unmanaged) /usr/lib/libmono.so.0(mono_runtime_invoke+0x27) [0x4009d551]
in (unmanaged) /usr/lib/libmono.so.0(mono_runtime_invoke_array+0x1e1)
[0x4009e33d]
in (unmanaged) /usr/lib/libmono.so.0 [0x400a3f13]
in <0x0009c> 00 System.Reflection.MonoCMethod:Invoke
(object,System.Reflection.BindingFlags,System.Reflection.Binder,object[],Sys
tem.Globalization.CultureInfo)
--- End of inner exception stack trace ---

in <0x000ab> 00 System.Runtime.Remoting.Proxies.RealProxy:PrivateInvoke
(System.Runtime.Remoting.Proxies.RealProxy,System.Runtime.Remoting.Messaging
.IMessage,System.Exception&,object[]&)
in (unmanaged) 07 NRemotingType.RemotableType:.ctor ()
in <0x00004> 07 NRemotingType.RemotableType:.ctor ()
in <0x00031> 08 NRemotingType.RemotableType:.ctor ()
in <0x000d1> 00 NRemotingTestClient.Client:Connect (string,int)
in <0x0003d> 00 NRemotingTestApp.MainClass:Init ()
in <0x00029> 00 NRemotingTestApp.MainClass:Main (string[])

wilhelmp@LINUX-S-01:~/src/RemotingTest/bin/Debug>

############################################################################
#########

Any ideas what's wrong?

Thank you!