Skip to content

Instantly share code, notes, and snippets.

@breezhang
Last active October 2, 2015 01:38
Show Gist options
  • Save breezhang/2146363 to your computer and use it in GitHub Desktop.
Save breezhang/2146363 to your computer and use it in GitHub Desktop.
Client just for test
public class MyRemoteClass : MarshalByRefObject, IMyInterface
{
public int FunctionOne(string str)
{
return str.Length;
}
}
Client some stuff
namespace Client
{
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using System.Runtime.Remoting.Messaging;
using ClientA;
static class MyClient
{
private delegate int MyDelegate(string s);
public static void Main()
{
var mTcpChan = new TcpChannel(9999);
ChannelServices.RegisterChannel(mTcpChan);
RemotingConfiguration.RegisterWellKnownServiceType(
Type.GetType("ClientA.MyRemoteClass,ClientA"),
"FirstRemote", WellKnownObjectMode.SingleCall);
// ChannelServices.RegisterChannel(m_TcpChan);
var m_RemoteObject = (IMyInterface)
Activator.GetObject(typeof(IMyInterface),
"tcp://vivi-pc:9999/FirstRemote");
var m_delegate =
new MyDelegate(m_RemoteObject.FunctionOne);
m_delegate.BeginInvoke("Amazing",
new AsyncCallback(MyCallBack), null);
System.Console.WriteLine("Press ENTER to quit");
System.Console.ReadLine();
}
private static void MyCallBack(IAsyncResult ar)
{
int l = ((MyDelegate)((AsyncResult)ar).AsyncDelegate).EndInvoke(ar);
Console.WriteLine(l);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment