Math Client : Http Channel « Network « C# / C Sharp






Math Client


using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Http;

public class MathClient
{
   public static int Main(string[] argv)
   {
      HttpChannel chan = new HttpChannel();
      ChannelServices.RegisterChannel(chan);
      MathClass obj = (MathClass)Activator.GetObject(
          typeof(MathClass), "http://127.0.0.1:9050/MyMathServer");
      if (obj == null) 
         System.Console.WriteLine("Could not locate server");
      else
      {
         int a = Convert.ToInt32(argv[0]);
         int b = Convert.ToInt32(argv[1]);
         int c = obj.Add(a, b);
         Console.WriteLine("a + b = {0}", c);
         c = obj.Subtract(a, b);
         Console.WriteLine("a - b = {0}", c);
         c = obj.Multiply(a, b);
         Console.WriteLine("a * b = {0}", c);
         c = obj.Divide(a, b);
         Console.WriteLine("a / b = {0}", c);
      }
      return 0;
    } 
}


public class MathClass : MarshalByRefObject
{
   public int Add(int a, int b)
   {
     int c = a + b;
     return c;
   }

   public int Subtract(int a, int b)
   {
      int c = a - b;
      return c;
   }

   public int Multiply(int a, int b)
   {
      int c = a * b;
      return c;
   }

   public int Divide(int a, int b)
   {
      int c;
      if (b != 0)
         c = a / b;
      else
         c = 0;
      return c;
   }
}

           
       








Related examples in the same category

1.HttpChannel Math Server
2.New Math Client