Having Trouble building a distributed calculator system with C sharp

Dinura Seneviratne

Can someone help me with this? This code is intended to to take 2 numbers from a client system and use the Clientserver Code to add the two numbers and return the number to the client, but as it is , the when the numbers are entered, there is simply no output

Code for The Client

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CalcService;

namespace CalcClient
{
    class Program
    {
        static void Main(string[] args)
        {
            Type requiredType = typeof(ICalculator);
            ICalculator proxyRemoteObject = 
                (ICalculator)Activator.GetObject(requiredType, "tcp://10.10.10.10:500/Serverone");

            Console.WriteLine("Number 1: ");
            int number1 = Convert.ToInt32(Console.ReadLine());

            Console.WriteLine("Number 2: ");
            int number2 = Convert.ToInt32(Console.ReadLine());

            int answer = proxyRemoteObject.AddNumbers(number1, number2);
            Console.WriteLine("Answer: " + answer);

            Console.ReadLine();
        }
    }
}

Code for The Service

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CalcService
{
    public interface ICalculator
    {
        int AddNumbers(int number1, int number2);
    }
}

Code for The Server

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Remoting.Channels.Tcp;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting;
using CalcService;

namespace CalcServer
{
    class Program
    {
        static void Main(string[] args)
        {
            TcpChannel channel = new TcpChannel(500);
            ChannelServices.RegisterChannel(channel,false);

            RemotingConfiguration.RegisterWellKnownServiceType(typeof(MyCalculator), "Serverone", WellKnownObjectMode.SingleCall);

            Console.WriteLine("Server is running");
            Console.ReadLine();
        }
    }

    public class MyCalculator: MarshalByRefObject, ICalculator
    {
        public int AddNumbers(int num1, int num2)
        {
            return num1 + num2;
        }
    }
}
Dinura Seneviratne

Changing The server to 127.0.0.1 solved the problem! Sorry for wasting anyones time. Thank you user Henk!

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related