473,396 Members | 1,921 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Remoting->Delegate

Hi,

I Wonder... Can a server-side class exposed through remoting expose a
delegate? In other words: can a client set a server-side delegate that
in-turn will be asynchronously called from the server on the client?

Thanks,
Nadav.
Nov 15 '05 #1
1 4765
Yes, that is possible. But there are two caveats:

1. A server can only call back to a client if the client has registered
a remoting channel. Callbacks are transported over a separate TCP
connection, which might be problematic in the presence of firewalls.

You can avoid using callbacks by having the client actively query for
events. It is a less convenient programming style, however.

2. Delegates are marshalled by value. This means that the delegate's
target object reference and its method info object are sent over the
wire. This implies that the receiver must have the metadata for the
target object.

This is probably not what you want. A cleaner solution is to use
interfaces. For example, instead of

delegate void MyEventHandler(int x);

use the following interface

interface IMyInterface {
void MyEvent(int x);
}

This way, the object is marshalled by reference and only the metadata
for the interface needs to be shared between the client and the server.

Consider the following server interface:

public delegate void NewMessageHandler(int messageId);
public delegate void MailboxFullHandler();

public interface IMailServer {
string GetMessageBody(int messageId);
event NewMessageHandler NewMessage;
event MailboxFullHandler MailboxFull;
}

This design suffers from the disadvantages associated with delegates as
discussed above. It also requires a separate connection from the server
to the client.

A design that avoids delegates, but that still requires a client channel
looks like this:

public interface IMailEventSink {
void NewMessage(int messageId);
void MailboxFull();
}

public interface IMailServer {
string GetMessageBody(int messageId);
void SetMailEventSink(IMailEventSink sink);
}

A design which avoids a client channel looks like this:

[Serializable]
public class MailEvent {
}

public class NewMessageEvent : MailEvent {
public int messageId;
}

public class MailboxFullEvent : MailEvent {
}

public interface IMailServer {
string GetMessageBody(int messageId);
MailEvent GetEvent();
}

The GetEvent method blocks until an event is available.

Happy coding!

Bart Jacobs

Nov 15 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Maurice | last post by:
Our product is build using the .NET framework 1.1. We have WinForm application that communicates a server via Remoting (tcp channel). We have two ways communication: From application to...
0
by: jan v | last post by:
Hi everyone I have a problem with events. When the code reaches communication.SynchronisationServer.UpdateNotificationEvent+=new...
15
by: Sharon | last post by:
I’m trying to build a generic Publisher-Subscriber that will work over the net, so I’m using the Remoting. I wish that the subscriber user will be notify about the messages sent by the...
4
by: Uchiha Jax | last post by:
Hello everyone, I am a plenty silly person who is trying to learn .NET remoting through trial and error (all articles I read are going over my head at the moment (mostly) so I thought i'd give...
2
by: Sharon | last post by:
I have a Form class that can be open by parent Form or by .NET Remoting command. When the parent Form opens the Form - All fine ! But when the .NET Remoting command is trying to Show the Form, the...
6
by: AMDRIT | last post by:
Hello folks, I appologize for the cross post, but I really need an answer on this: I do not think that I am seeing the whole picture here. I would like to create a windows service and a...
2
by: Sagaert Johan | last post by:
Hi When the remoting server starts and the client immediate begins calling the remote object on the server no problems. But when the client does not need to access the remote object for some...
13
by: Brosto | last post by:
Hello, I'm writing a server client application and I'm having a terrible time getting one section to work. This is my first time using .net remoting, so please bear with me if I'm doing...
4
by: Rich | last post by:
Can anyone suggest a good (current) tutorial on how to do basic remoting with C# (2005 express edition)?
0
by: =?Utf-8?B?Sm9obiBXLg==?= | last post by:
I am using Remoting (TCP) to access a singleton object in one app (a service) from another app (call it app #2). Using the methods described in competent literature, the server raises an event...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.