|
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Http;
using System.Runtime.Remoting.Messaging;
using ClientServer;
namespace ClientTest
{
class Program
{
static IRemoteObject remObj;
static void Main(string[] args)
{
ChannelServices.RegisterChannel(new HttpChannel(9834), false);
CallbackSink sink = new CallbackSink();
sink.OnHostToClient += new ReturnEvent(sink_OnHostToClient);
remObj = (IRemoteObject)Activator.GetObject(typeof(IRemoteObject), "http://10.0.0.129:8086/Execute");
if (remObj == null)
{
Console.WriteLine("could not locate server");
return;
}
try
{
remObj.RegisterCallback(new ReturnEvent(sink.HandleToClient));
}
catch (Exception ex)
{
}
string scriptCode = @"using System;
using System.Windows.Forms;
public class TestClass
{
static public void Main(string[] args)
{
if(args.Length > 0)
{
MessageBox.Show(args[0]);
Console.WriteLine(args[0]);
}
else
{
MessageBox.Show(String.Empty);
Console.WriteLine(String.Empty);
}
}
}";
remObj.ExecuteCode(scriptCode, "*.Main", new string[] { "Helloooooooo" });
//remObj.ExecuteCode(scriptCode, "*.Main", null, false);
Console.WriteLine("Data had been sent...");
Console.ReadLine();
}
static bool firstTime = true;
static void sink_OnHostToClient(ReturnEventArgs e)
{
if (e.CodeException != null)
Console.WriteLine("damn it!!! code exception.");
if(e.ExecuterException != null)
Console.WriteLine("damn it!!! executer exception.");
else if (e.CodeException == null && e.ExecuterException == null)
{
Console.WriteLine("Hurraaaaaaaaaa!!!");
if (firstTime)
{
ExecuteByHash(e.HashCode);
firstTime = false;
}
}
}
private static void ExecuteByHash(string p)
{
remObj.ExecuteAlreadyExecuted(p, "*.Main", new string[] { "Helloooooooo" });
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I'm an undergraduate student of IT.
I'm a C# programmer and have some experience in robotics, image processing, telephony systems, etc.