REMOTING
REMOTING IS AN TECHNIQUE
THROUGH WE CAN CREATE DISTRIBUTED APPLICATION AND TO COMMUNICATION BETWEEN
THOSE APPLICATION
PROCESS 1 ISOLATE
PROCESS 2
REMOTING IS AN TECHNIQUE TO DO
INTERPROCESSOR COMMUNICATION BETWEEN TWO PROCESS
IN JAVA RMI (Remote Method Invocation)
IN .NET REMOTING
THESE PROCESS MAY BE RUN AT ANY WHERE
AT SEVER MACHINE OR AT DIFFERENT MACHINE
EACH APPLICATION BY DEFAULT CREATE
IT’S OWN APPLICATION DOMAIN.
REMOTING IS AN SERVER CLIENT
ARCHITECTURE
SERVER APPLICATION
CLIENT
APPLICATION
SERVICE
SERVER APPLICATION MUST BE ACTIVE
TO MAKE THE CONNECTION BETWEEN SERVER AND CLIENT.
TWO MODES
SINGLETON : OBJECECT IS REMOVED AND FIXED ON SERVER
SIDE
SINGLE CALL : OBJECT IS NOT FIXED WE DESTROY THIS OBJECT
AFTER WORK.
NON REMOTABLE OBJECT NON REMOTABLE OBJECT ARE THOSE OBJECT WHICH
NEVER CROSS THEIR BOUNDRY
REMOTABLE OBJECT REMOTABLE OJECT ARE THOSE OBJECT WHICH CAN
BE ACCESS OUT OF THE BOUNDRY TO MAKE A REMOTABLE OBJECT USE THIS CLASS.
MARSHALBYREFOBJECT IS
AN CLASS
REMOTING TERMS WHICH COME IN REMOTING ENVIRONMENT
PROXY
CHANNELS
MESSAGE
FORMATTERS
PROXY
PROXY IS AN FAKE COPY AT
CLIENT HAND SIDE TO ACCESS THE ACTUAL OBJECT AS THOSE ARE CREATED ON SERVER
SIDE. AND THE CREATION OF FAKE COPY IS DONE BY CLR.
TO GENERATE OR CREATE PROXY USE THIS
ACTIVATOR.GETOBJECT( );
IDENTIFICATION OF THE PROCESS BY PORT NUMBER
SMTP PORT NO. IS 25;
IP ADDRESS + PORT NO. TO ACCESS AN PROCESS OR TO IDENTIFY AN PROCESS
CHANNELS CHANNELS ARE PROGRAMS IN WHICH THE
TRANSPORTATION IS OCCUR BETWEEN CLIENT AND SERVER AND SERVER TO CLIENT SIDE OF
A FILE. AT DATA NETWORK DATA CAN BE IN BINARY FORM
HTTP CHANNEL
IPC
CHANNEL
TCP
CHANNEL ( SO FAST AND BINARY FORM)
IPC CHANNEL
Inter-Process
Communication IPC is a set of techniques for the exchange of data among two or
more threads in one or more processes. Processes may be running on one or more
computers connected by a
IPC CHANNELS NOT SUPPORT ANY
NETWORK LAYER, SO IT IS USED WHEN THE CLIENT AND SERVER BOTH ARE AT SAME
MACHINE.
SAOP
(SIMPLE ACCESS OBJECT PROTOCOL)
SAOP MESSEGE CAN BE UNDERSTAND BY
ANY TECHNOLOGY IT IS STANDARD FORMAT BY W3C
TO SEND TO HETEROGENEOUS SYSTEM USE SAOP
FORMATTER
IS PLAY AN IMPORTANT ROLE TO FORMAT AND TO CONVERT THE DATA
TWO TYPES OF FORMATTER ARE
BINARY
FORMATTER
SAOP
FORMATTER
CHANNEL IS
FOR TRANSPORTER
FORMATTER
IS FOR ENCODER
PRACTICAL
1.
CLIENT APPLICATION
2.
SERVER APPLICATION
3.
SERVICE APPLICATION
PRACTICAL
EXAMPLE OF PRIVATE CHAT
FIRSTLY CREATE SERVICE APPLICATIONS
1.
ADD AN
CLASS LIBRARY FOR INTERFACE NAMING OF FUNCTIONS
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace Ichat
{
public interface Ichatting
{
void
setmessage(string to, string
from, string mess);
string
getmessage(string user);
ICollection
Getusers();
void
adduser(string nm);
}
}
2.
THEN
CREATE ANOTHER CLASS LIBRARY FOR IMPLEMENTATION OF THESE FUNCTIONS
· AND ADD A REFRENCE THIS ICHAT CLASS LIBRARY
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ClassLibrary10
{
public class Chat:MarshalByRefObject,Ichat.Ichatting
{
Dictionary<string, string> dc
= new Dictionary<string, string>();
#region Ichatting Members
public
System.Collections.ICollection Getusers()
{
return
dc.Keys;
}
public void adduser(string
nm)
{
dc.Add(nm,"");
}
public string getmessage(string
user)
{
if
(dc.ContainsKey(user))
{
return
dc[user];
}
return
null;
}
public void setmessage(string
to, string from, string
mess)
{
dc[to] = from + ":" + mess + Environment.NewLine;
dc[from] =from + ":" + mess + Environment.NewLine;
}
#endregion
}
}
3. THEN CREATE SERVER
APPLICATION
·
ADD A REFRENCE YOUR BOTH
CLASS LIBRARY OF SERVICES
·
ADD A REFRENCE USING SYSTEM.RUNTIME.REMOTING NAMESPACE
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Remoting;
using
System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
namespace ConsoleApplication4
{
class Program
{
static void Main(string[]
args)
{
TcpChannel
tc = new TcpChannel(8086);
ChannelServices.RegisterChannel(tc);
RemotingConfiguration.RegisterWellKnownServiceType(typeof(ClassLibrary10.Chat),
"chat", WellKnownObjectMode.Singleton);
Console.WriteLine("server is running");
Console.ReadLine();
}
}
}
4.
THEN
CREATE CLIENT APPLICATION
CREATE TWO FORMS
FOR FORM 1
CODING
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication39
{
public partial class Form1 : Form
{
public
Form1()
{
InitializeComponent();
}
public static string user;
private
void button1_Click(object
sender, EventArgs e)
{
user = textBox1.Text;
Form2
obj = new Form2();
obj.Show();
}
private
void Form1_Load(object
sender, EventArgs e)
{
}
}
}
IN FORM2
CODING
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication39
{
public partial class Form2 : Form
{
public
Form2()
{
InitializeComponent();
}
private
void button1_Click(object
sender, EventArgs e)
{
obj.setmessage(comboBox1.SelectedItem.ToString(), Form1.user, textBox2.Text);
}
Ichat.Ichatting
obj;
private
void Form2_Load(object
sender, EventArgs e)
{
obj = (Ichat.Ichatting)Activator.GetObject(typeof(Ichat.Ichatting),
"tcp://localhost:8086/chat");
obj.adduser(Form1.user);
label1.Text = Form1.user;
}
private
void timer1_Tick(object
sender, EventArgs e)
{
foreach
(string s in
obj.Getusers())
{
if
(!comboBox1.Items.Contains(s))
{
comboBox1.Items.Add(s);
}
}
string
str = obj.getmessage(Form1.user);
textBox1.Text = str;
}
}
}
No comments:
Post a Comment