[Mono-dev] Remoting Server Events problem

buhochileno at gmail.com buhochileno at gmail.com
Mon Nov 26 20:45:32 EST 2007


Hi Robert:

I finally understend your code and work like a charme!!!, thanks a lote, 
is a very nice and clean remoting event implementation...,
I don't want take advantage of your kind help, but I have a 
"distributed" scenario on my app, and I wonder if you have some suggestions:
- I understend your code and the server/client relationship with the 
AsyncEvents schema, is very good to traslate messages from the server to 
the client, but in my case the server have to expose other app objects 
than the server itself, let me explain me a littel bit:
My app is something like the new Visual Robotics from MS, but this 
"monoBotic" is for the opensource comunity, so I have a lost off classes 
like Motor, MotorsController, Sensor, WebCam, RobotKit, etc...
for example I have a WebCamOrbit traditional class (inherit from a base 
abstract class, implements interface and all that kind of stuff), the 
class deal with all the stuff related with the logitech webcam orbit (a 
pan/tilt webcam), the class also have some events like 
OnPositionChange(object  e, PanTiltEventArgs e), and  some methods like 
SetPanTilt(int pan, int tilt) (this method  also trigger the 
OnPositionChange event...)...In the monoBotic the programmer can choose 
a "local WebCamOrbit object" is the robotic app is going to run in the 
same robot machine (for example a PC based robot or other sensors/motors 
connected directly to the PC), this is easy becouse in this scenario I 
only have to create a instance of WebCamOrbit, but in other scenarios 
the programmer perhaps want a "remoting WebCamOrbit object" becouse 
perhaps the camera is connected in other machine and maybe in one 
machine ask for the image in a camera in other machine, analyse the 
image and send the result and take advantache of the remotung technologie.
So, all this is going to be possible to make "by hand" using the 
monoBotic framework if you are a programmer, but also monoBotic want to 
generate some code to make things easy. So, if is possible the "local 
version" of the WebCamOrbit and the "remote version" have to be the most 
similar as possible (method calls, event asociation, etc...)
Thow I was thinking in may be have the traditional WebCamOrbit for local 
porpuses and also a ServerWebCamOrbit and also a ClientWebCamOrbit.
In the server side each object that is intended to use with remoting 
(like the WebCamOrbit or a Motor, etc) is like a "remoting 
server"(ServerWebCamOrbit) and deals with the AsyncEvent and make the 
bindings with the traditional WebCamOrbit.
In the client side, the ClientWebCamOrbit get the remote 
ServerWebCamOrbit object and implement the necesary bindigs to look to 
the programer as a traditional WebCamOrbitObject (may be with diferent 
contructor to pass the object URL..etc).

This sounds like have any sense to you? :-S , I think that in this way I 
can controll the methods and events that can be handled with remoting 
and not expose all the methods and events from the original WebCamOrbit, 
but the problem is I need to have a "Remoting Server" for each object, 
in fact in this escenario, each object that is supose to work in a 
remotng way is a server.
And in the client side with the client version of the class, I can make 
all the necesary bindigs to expose the client version of the object as 
similar as is posible to the traditional/local WebCamOrbit...But 
offcourse all this is not ver scalable and need a lote of code to 
maintein each server and client version of each class...

So, I need a lote of design help I think ... :-S

Sorry to bored you with such a long mail...
And in advance, thank you very much..

Mauricio.

Robert Jordan wrote:
> Hi,
>
> buhochileno at gmail.com wrote:
>> Thanks Robert, I very confuse with this, becouse I read a lote of 
>> diferent approach (event broadcast engines, shared objects, etc) to 
>> do this, but most of them don't work :-S ,  I wondore if you have a 
>> simple working example of the correct way to do this?
>
>
> Events only make sense in local cross appdomain contexts.
> Anything else is a world of pain. See
> http://www.thinktecture.com/resourcearchive/net-remoting-faq/remotingusecases 
>
>
> The attached sample is still using events on the server side but
> it requires that clients implement a certain interface that
> was declared in the shared assembly.
>
> The server is using a special "AsyncEvent" that doesn't have the
> drawbacks of a simple CLI event:
>
> - the clients are notified sequentially. This doesn't scale
>
> - if a client doesn't respond, the next clients won't be called
>   back anymore. This is far from being reliable.
>
> AsyncEvent is calling the clients in parallel and it also disconnects
> failing clients. This is still not optimal because it doesn't scale
> at large: Imagine you have 1000 connected clients ...
>
> Robert
>
>>
>> in advance, thank you very much.
>>
>> Mauricio
>>
>> Robert Jordan wrote:
>>> buhochileno at gmail.com wrote:
>>>  
>>>> Hi:
>>>>
>>>> I know that is very possible that this is a basic remoting 
>>>> question, but I read some info about the native .NET approach used 
>>>> with remoting and I think that my code is supose it to work:
>>>>
>>>> I write a class with a method to trigger some event (this is the 
>>>> object resgitered by the remoting server):
>>>> [Serializable]
>>>> public class Camera: MarshalByRefObject
>>>> ...
>>>>    public void SetZoom(int amount)
>>>>    {...//zoom code
>>>>        SomeDelegate h = this.SomeEvent; //some test event triger, 
>>>> the SomeDelegate is public...
>>>>        if ((h != null) && (SomeEvent != null))
>>>>                h (this, new EventArgs());
>>>>        else
>>>>                Console.WriteLine("null then?"); //allways is null
>>>>       }
>>>> ...On the client side I use a special "RemoteCamera", this class 
>>>> deal with all the remoting stuff related to get the object from the 
>>>> server...something like:
>>>> [Serializable]
>>>> public class RemoteCamera: MarshalByRefObject
>>>>        public RemoteOrbitKit()
>>>>        { .../channel registration, etc...
>>>>             
>>>> camera(ICamerat)Activator.GetObject(typeof(ICamera),_fullObjectURLPath); 
>>>> //....
>>>>            camera.SomeEvent += new SomeDelegate(SomeMethod);
>>>>             ...
>>>>             camera.SetZoom(50); //this work, but the event is not 
>>>> triggered...
>>>>
>>>>        }
>>>>        public SomeMethod(object sender, EventArgs e)
>>>>        {
>>>>             Console.WriteLine("method called"); //This methis is 
>>>> never called becouse the Event/method asociation allways is null
>>>>        }
>>>>
>>>> Do you see what is my mistake?
>>>> sugestions?, ideas?
>>>>     
>>>
>>> 1. The server must know the type "RemoteCamera", because the delegate
>>>     is containing a reference to an instance of this class.
>>>
>>>     You can circumvent this by using a public static method as
>>>     an event handler.
>>>
>>> 2. The client must start a listener as well. This is done with
>>>     "new TcpChannel (0)" or "new HttpChannel (0)" or with a
>>>     corresponding remoting configuration setting.
>>>
>>> 3. The client must not be firewalled because it is
>>>     called back by the server.
>>>
>>> Robert
>>>
>>> _______________________________________________
>>> Mono-devel-list mailing list
>>> Mono-devel-list at lists.ximian.com
>>> http://lists.ximian.com/mailman/listinfo/mono-devel-list
>>>
>>>   
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list
>   




More information about the Mono-devel-list mailing list