且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

远程客户端 - 服务器应用程序无法接受传入邮件

更新时间:2023-11-14 10:17:22

服务器代码

创建新频道监听在 port 8085

Create a new channel listening communicating on port 8085

TcpChannel channel = new TcpChannel(8085);

使用远程管理服务注册。

Register with remoting channel services.

ChannelServices.RegisterChannel(channel);

告诉远程处理我们使用RemoteObject类型的服务,应该创建一次。

Tell remoting that we are using a service of type RemoteObject and it should be created once.

RemotingConfiguration.RegisterWellKnownServiceType(typeof(RemoteObject), "myobject", WellKnownObjectMode.Singleton);

Readline只是用于等待输入(在退出控制台应用程序之前)。

Readline is simply used to wait for enter (before exiting console application).

Console.ReadLine();

Console.ReadLine();

客户端代码

与服务器端相同

TcpChannel channel = new TcpChannel();
ChannelServices.RegisterChannel(channel);

创建远程代理代理,它在8085端口的localhost上与服务器进行通信,并使用RemoteObject

Create a remoting proxy proxy which communicates with server at localhost on port 8085 and used RemoteObject

RemoteObject remoteObject = (RemoteObject)Activator.GetObject(typeof(RemoteObject), "tcp://localhost:8085/myobject");

向服务器发送邮件

remoteObject.PrintMessage("Hello world!");

最后字词

您可以向RemoteObject类中添加更多方法来构建一个完整的聊天应用程序。

You can add more methods to the RemoteObject class to build a complete chat application.

另请参阅远程回调。你的教授有点过时了。 Remoting已被微软的WCF所取代。

Also read about remoting callbacks. Your professor is a bit out of date. Remoting have been replaced by WCF by microsoft.