![]() |
General Programming »
Internet / Network »
Remoting
Intermediate
.NET Remoting SampleBy Helmut GüldenagelShows how to use .NET Remoting for beginners. |
C#, Windows, .NET 1.1VS.NET2003, Dev
|
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||
Why am I publishing this sample?
Because it is very difficult to find working code in the MSDN or internet. Most samples require awkward config files or they are much too complicated for beginners. This sample runs immediately and does not require config files.
The original intention was to remote control an application on a slave computer via network. The master sends a command and waits for the slave until it executes the remote command. This sample sends only text strings, but it can easily be expanded to transfer anything. (See class cTransfer.)



There a three major ways to use .NET Remoting (this sample uses the first one):
(Object is created locally and then published.)
ChannelServices.RegisterChannel (new TcpChannel(1500));
cTransfer Trans = new cTransfer();
RemotingServices.Marshal (Trans, "TestService");
cTransfer T = (cTransfer) Activator.GetObject(typeof(cTransfer),
"tcp://host:1500/TestService");
(Object is created on request of client)
ChannelServices.RegisterChannel (new TcpChannel(1500));
RemotingConfiguration.RegisterWellKnownServiceType(typeof(cTransfer),
"TestService", WellKnownObjectMode.Singleton);
cTransfer T = (cTransfer) Activator.GetObject(typeof(cTransfer),
"tcp://host:1500/TestService");
(Object is created on host and client receives a reference to it)
ChannelServices.RegisterChannel (new TcpChannel(1500));
RemotingConfiguration.RegisterActivatedServiceType(typeof(cTransfer));
object[] attr = {new UrlAttribute("tcp://host:1500")};
object[] args = {"Sample constructor argument"};
cTransfer T = (cTransfer) Activator.CreateInstance(typeof(cTransfer), args, attr);
Notes:
cTransfer is a class which is defined in Remoting.DLL. It contains the variables and an event to communicate between Host and Client.
This should be enough of explanation. Look into the source code: it's really simple!
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 14 Apr 2005 Editor: Sean Ewington |
Copyright 2005 by Helmut Güldenagel Everything else Copyright © CodeProject, 1999-2009 Web11 | Advertise on the Code Project |