Click here to Skip to main content
15,920,596 members
Articles / Operating Systems / Windows
Article

My First Remoting Experience

Rate me:
Please Sign up or sign in to vote.
3.41/5 (7 votes)
14 Mar 2006CPOL3 min read 35.2K   624   25   1
A really simple example on how to use remoting correctly in many ways
Sample Image - Remoting_for_Dummies.jpg

Introduction

I decided to post this article because I never found what I was looking for on the Web. What I needed was an application that could "understand" what another application was saying. I'd found tons of examples of remoting and the simple Hello World! example, and of course the one where you can see the creation of an instance on the server for one of the object's attributes on the client. But that was not what I needed. I wanted to create an object, set its attributes and send it over the network to a different application which was programmed to do something with that object.

As Muhammad Musa Ali suggested, I'll explain a little bit more about remoting in case you have no clue what it is good for. Let's say you're building an IM app. You have to communicate with others through the network (for a start, let's just talk about a LAN). With the .NET technologies, you could open a TcpClient connection and use a NetworkStream in order to send strings over the network. You could "create" your own SOAP protocol in order to send more than one information to the other client as to who is sending the message, at what time the message was sent and so on. But if you could send an object of your domain, what if you could have a Message class with attributes as ID, text, time, and client, where client is an instance of a class also from your domain with attributes such as name, IP, address, state, etc. Well, that's what remoting is for.

Background

I believe that if you're reading this, you are familiar with remoting and serialization, and you want an example of it. If that's not your case, I'd recommend you to read a little bit about them and then run the code.

Using the Code

This solution is really simple, it has three projects in it (Client, DLL and Server). The DLL project has an interface (ILogic) and a class (Client). This Client class is the one I will create on one application, set its attributes and send it over the network to a different app (Server). The ILogic is an interface implemented by the server in the Logic class. The three methods exposed by the interface are the ones the client app sees. The Client app has a simple form from which you execute methods from the server and one of them has a client object as a parameter.

So, to get it running, just right click on the Server project and under the Debug item click on Start new instance. After that, do the same as many times as you wish with the client project. When the client form appears, click the "Mensaje" button and take a look at the console. After that, just play around with the other buttons and messages.

Take a look at the "Hora" button and what you see on the console. Compare the two, amazing isn't it?

Bottom Line

It is really easy to use remoting and if you are in a controlled and closed environment, remoting is the right tool for you. But keep in mind that if you need to interact with some application outside your LAN, Web services would be the right tool for you. As you may have noticed, Web services are just a particular implementation of remoting.

History

  • 14th March, 2006: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
Uruguay Uruguay
Sebastian Gomez is a System Engineer in Uruguay, South America.
He's been working with .net technologies since beta 1.

You can reach Sebastian at: SebastianGomezCorrea[at]gmail.com

Comments and Discussions

 
Generalvery nice demo and example Pin
Muhammad Musa Ali14-Mar-06 11:09
Muhammad Musa Ali14-Mar-06 11:09 
... very nice effort in terms of demo and code.

This may become more beneficial if you could write a few more lines explaining the underlying concepts.

I believe it might have served as a very nice tutorial for beginners to remoting, should you have taken some time and written it in a more descriptive way.

Anyway, still a very good effort !!

Muhammad Musa Ali,
MCAD, MCSD - Early Achiever in .NET

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.