C#中的简单远程处理 [英] Simple Remoting in c#
本文介绍了C#中的简单远程处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
server.cs
server.cs
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
namespace RemotingSamples {
public class Sample {
public static int Main(string [] args) {
TcpChannel chan = new TcpChannel(8085);
ChannelServices.RegisterChannel(chan);
RemotingConfiguration.RegisterWellKnownServiceType
(Type.GetType("RemotingSamples.HelloServer,object"),
"SayHello", WellKnownObjectMode.SingleCall);
System.Console.WriteLine("Hit <enter> to exit...");
System.Console.ReadLine();
return 0;
}
}
}
</enter>
client.cs
client.cs
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
namespace RemotingSamples {
public class Client
{
public static int Main(string [] args)
{
TcpChannel chan = new TcpChannel();
ChannelServices.RegisterChannel(chan);
HelloServer obj =
(HelloServer)Activator.GetObject(typeof(RemotingSamples.HelloServer)
, "tcp://localhost:8085/SayHello");
if (obj == null)
System.Console.WriteLine("Could not locate server");
else Console.WriteLine(obj.HelloMethod("Caveman"));
return 0;
}
}
}
object.cs
object.cs
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
namespace RemotingSamples {
public class HelloServer : MarshalByRefObject {
public HelloServer() {
Console.WriteLine("HelloServer activated");
}
public String HelloMethod(String name) {
Console.WriteLine("Hello.HelloMethod : {0}", name);
return "Hi there " + name;
}
}
}
makefile
makefile
all: object.dll server.exe client.exe
object.dll: share.cs
csc /debug+ /target:library /out:object.dll object.cs
server.exe: server.cs
csc /debug+ /r:object.dll /r:System.Runtime.Remoting.dll server.cs
client.exe: client.cs server.exe
csc /debug+ /r:object.dll /r:server.exe
/r:System.Runtime.Remoting.dll client.cs
这些是我从此处
获得的代码
如何使这个简单的远程应用程序运行?
请逐步解释它.
These are the codes I get from here
How do I get this simple remoting application run?
Please explain it step by step.
推荐答案
要使用 makefiles ,您需要打开 Visual Studio命令提示符 >并运行 nmake 实用程序.在此处查看 [
To use makefiles you need to open the Visual Studio command-prompt and run the nmake utility. Look here[^] for a reference on it.
答案很简单:使用 makefile 编译3个对象:获得server.exe
,client.exe
和object.dll
.
然后运行server.exe
,然后运行client.exe
The answer is so simple: use the makefile to compile the 3 objects: you obtainserver.exe
,client.exe
andobject.dll
.
Then runserver.exe
and after that runclient.exe
这篇关于C#中的简单远程处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文