DS Experiment no 9 (UPDATED)



Aim- Use .Net framework to deploy a distributed application.



ShowCapital(Library File)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;

namespace newclass{
    public class ShowCapital : MarshalByRefObject{
        public ShowCapital()
{  }
        public string show(string country)
        {
            if (country.ToLower() == "england") return ("London");
            else if (country.ToLower() == "scotland") return ("Edinburgh");
            else if (country.ToLower() == "india") return (" New Delhi");
            else if (country.ToLower() == "japan") return ("Tokyo");
            else if (country.ToLower() == "australia") return ("canberra");
            else if (country.ToLower() == "italy") return ("rome");
            else if (country.ToLower() == "south africa") return ("Pretoria");
            else if (country.ToLower() == "New zealand") return ("Wellington");
            else return ("Not known");
        }
}
}

Server.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;

namespace newclass2{
    class Program{
        static void Main(string[] args){
            TcpServerChannel channel = new TcpServerChannel(1234);
            ChannelServices.RegisterChannel(channel, false);
            RemotingConfiguration.RegisterWellKnownServiceType
            (typeof(newclass.ShowCapital), "ShowCapital",
            WellKnownObjectMode.SingleCall);
            Console.WriteLine("Starting...");
            Console.ReadLine();  }
}
}




Client.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using newclass;
namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        ShowCapital sh;
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            TcpClientChannel channel = new TcpClientChannel();
            ChannelServices.RegisterChannel(channel, false);
            RemotingConfiguration.RegisterWellKnownClientType(
            typeof(ShowCapital), "tcp://localhost:1234/ShowCapital");
            sh = new ShowCapital();

        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            string country, cap;
            country = textBox1.Text;
            cap = sh.show(country);
            textBox2.Text = cap;
        }
    }
}








DS Experiment no 9 (UPDATED) DS Experiment no 9 (UPDATED) Reviewed by Akshay Salve on 11:57 PM Rating: 5

No comments:

Powered by Blogger.