📄 ex-19-03
字号:
// Example 19-03: The Calculator server
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Http;
namespace Programming_CSharp
{
// implement the calculator class
public class Calculator : MarshalByRefObject, ICalc
{
public Calculator()
{
Console.WriteLine("Calculator constructor");
}
// implement the four functions
public double Add(double x, double y)
{
Console.WriteLine("Add {0} + {1}", x, y);
return x+y;
}
public double Sub(double x, double y)
{
Console.WriteLine("Sub {0} - {1}", x, y);
return x-y;
}
public double Mult(double x, double y)
{
Console.WriteLine("Mult {0} * {1}", x, y);
return x*y;
}
public double Div(double x, double y)
{
Console.WriteLine("Div {0} / {1}", x, y);
return x/y;
}
}
public class ServerTest
{
public static void Main()
{
// create a channel and register it
HttpChannel chan = new HttpChannel(65100);
ChannelServices.RegisterChannel(chan);
Type calcType =
Type.GetType("Programming_CSharp.Calculator");
// register our well-known type and tell the server
// to connect the type to the endpoint "theEndPoint"
RemotingConfiguration.RegisterWellKnownServiceType
( calcType,
"theEndPoint",
WellKnownObjectMode.Singleton );
// "They also serve who only stand and wait."); (Milton)
Console.WriteLine("Press [enter] to exit...");
Console.ReadLine();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -