Click here to Skip to main content
15,878,748 members
Articles / Programming Languages / C#
Article

Remote Controlled Windows Application

Rate me:
Please Sign up or sign in to vote.
3.58/5 (14 votes)
1 Jul 20041 min read 63K   2.7K   53   7
How to let your Windows application be remote controlled

Image 1

Introduction

This small Windows application shows how to make your application or part of it be controlled from remote machines. The demo application just can flip an image and this is also what several remote clients can do.

Background

Since most of the samples I found on Internet about remoting do let the .Net runtime create the marshalled object in the hidden background,
I had to find a way to create and marshal my objects programmatically to provide it with a reference to my applications interface. This is just what my application demonstrates.

It also demonstrates how to minimize the dependencies from server and clients by accessing the remote object over interfaces. Here is the design pattern for decoupling the objects with interfaces.

Image 2

Using the code

The VS-Solution 'MyRemoteSampleApp.sln' holds the 3 projects: the application, the client and the remotable class.

  • MyServerApplication
  • MyClient
  • MyRemoteInterface

After starting 'MyServerApplication.exe' you can start as many clients 'MyClient.exe' as you like, which all connect to the same 'MyService' object.

Points of Interest

Create and marshal the object on server side in the applications 'Main()':

C#
TcpChannel channel = new TcpChannel(8080);
ChannelServices.RegisterChannel(channel);

// Create a single marshalled object
MyServiceClass remService  = new MyServiceClass();
ObjRef obj = RemotingServices.Marshal(remService,"TcpService");

// Create appllications MainForm
MainAppForm frmMain = new MainAppForm();

// provide the marshalled object with a reference to the Applications interface
remService.theMainForm = ( IAppRemote) frmMain;

// start application
Application.Run(frmMain);
Connect to the remote object on client side:
C#
// Interface reference
IMyService remServive = null;
...
...

// Get a TCP channel and register required service
ChannelServices.RegisterChannel(new TcpChannel());
WellKnownClientTypeEntry remotetype = new WellKnownClientTypeEntry(
  typeof(MyServiceClass),"tcp://localhost:8080/TcpService");
RemotingConfiguration.RegisterWellKnownClientType(remotetype);

// instantiates the proxy
remServive = new MyServiceClass();

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Switzerland Switzerland
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralObserver Pattern Pin
Lav Pathak11-Mar-05 10:03
Lav Pathak11-Mar-05 10:03 
GeneralCool . check it out www.dotnetremoting.com Pin
Htrough3-Feb-05 23:26
sussHtrough3-Feb-05 23:26 
GeneralRe: Cool . check it out www.dotnetremoting.com Pin
fatcat111126-Sep-05 9:44
fatcat111126-Sep-05 9:44 
GeneralRemoting Problems ... Pin
Paebbels24-Nov-04 6:25
Paebbels24-Nov-04 6:25 
Hi,

in this case it works fine but this project is designed for an local or an intranet application...

i need a way to use it at the internet.
i know it would work too, but i have to copy the DLL with the Interface declaration to all Clients.

My ServerApplication should be able to load unknown DLLs and provide them with remoting. So its not user friendly to copy new DLLs to the ClientApplication for every changing on the ServerApplication...

I thought of a possibility to load DLLs over Internet ...?
like
LoadDLL(http://server.tld/Application/AddOns/Interface.dll)

i hope you understand my problem, if not ask ^^

Copyrights © 2003 by Paebbels.net
GeneralIdle Time Pin
HMJ25-Jul-04 7:34
HMJ25-Jul-04 7:34 
GeneralRe: Idle Time Pin
jobr1ch25-Jul-04 20:31
jobr1ch25-Jul-04 20:31 
Generalthank you very much Pin
krssagar15-Jul-04 20:35
krssagar15-Jul-04 20:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.