How to deliver message to client without client call with remoting?
I am developping a message reminding system.I want to send message to the client through client IP address initiatively.But I don't know how to make it.Please tell me how!
Make your client object implement MarshalByRef, then pass an object to the server as an argument to a call. You can have a hastable of client references and unique id on the server and when you want to send a message back to a particular client retrieve the reference for that id and send a message.
In the example below, call MyServer.RegisterClientReference(<ClientObjectThatYouNeedCallbackToBeCalledOn>);
public class MyClient : MarshalByRef
public class MyServer : MarshalByRef
{
public void RegisterClientReference(MyClient clientCallback)
I used the second way to register event, but in this way I can't choose client I want to send message ,it's a broadcastint way.I want to send it to the client I want,but not every client. This is the part of client code:
wrapper.LocalBroadCastEvent += new BroadCastEventHandler(BroadCastingMessage); watch.BroadCastEvent += new BroadCastEventHandler(wrapper.BroadCasting);
watch is the remote object proxy,wrapper is a local MarshalByRefobject and server also have this class,BroadCastingMessage is local method which receives a message parameter.
First,I should call a server method,this method can fire the watch.BroadCastEvent for every client event register,then wrapper.BroadCasting method is called which fires wrapper.LocalBroadCastEvent , last local BroadCastingMessage method is called.
this is the main process.
Did I use this method in a incorrect way I just want to choose clients to send.Could you tell me the mistake I made or how to use the first way to pass mashalbyrefobject object to the server
Probably you need to try the first solution i.e. make the client call a method on a server and pass a MarshalByRef object that the server can then use to notify a single client. As you mentioned events is kind of a broadcast mechanism.
To send messages to your client, you need to open up a channel in your client for input. Depending on the type of channel you are using, there are diffrent ways this should be done. After you've opened up the incoming channel, you can then pass MarshalByRef objects from the client to the server that the server can then call methods on. You can also register for events on the server and receive callbacks that way. Either way, there would need to be some initial call from the client to let the server know about the client (some sort of sign on) After that the server can initiate calls to that client.
--Hoop
[MSFT]
How to deliver message to client without client call with remoting?
How to deliver message to client without client call with remoting?
pwrgener80r
Jibotang,
Make your client object implement MarshalByRef, then pass an object to the server as an argument to a call. You can have a hastable of client references and unique id on the server and when you want to send a message back to a particular client retrieve the reference for that id and send a message.
In the example below, call MyServer.RegisterClientReference(<ClientObjectThatYouNeedCallbackToBeCalledOn>);
public class MyClient : MarshalByRef
public class MyServer : MarshalByRef
{
public void RegisterClientReference(MyClient clientCallback)
}
Maheshwar Jayaraman [MSFT]
maehler
Hoop,
I used the second way to register event, but in this way I can't choose client I want to send message ,it's a broadcastint way.I want to send it to the client I want,but not every client. This is the part of client code:
IBroadCast watch = (IBroadCast)Activator.GetObject(typeof(IBroadCast),"http://"+strhost+"/BroadCastMessage.soap");
EventWrapper wrapper = new EventWrapper();
wrapper.LocalBroadCastEvent += new BroadCastEventHandler(BroadCastingMessage);
watch.BroadCastEvent += new BroadCastEventHandler(wrapper.BroadCasting);
watch is the remote object proxy,wrapper is a local MarshalByRefobject and server also have this class,BroadCastingMessage is local method which receives a message parameter.
First,I should call a server method,this method can fire the watch.BroadCastEvent for every client event register,then wrapper.BroadCasting method is called which fires wrapper.LocalBroadCastEvent , last local BroadCastingMessage method is called.
this is the main process.
Did I use this method in a incorrect way I just want to choose clients to send.Could you tell me the mistake I made or how to use the first way to pass mashalbyrefobject object to the server
HCF
Jigar Patel
Jibotang,
Probably you need to try the first solution i.e. make the client call a method on a server and pass a MarshalByRef object that the server can then use to notify a single client. As you mentioned events is kind of a broadcast mechanism.
Maheshwar Jayaraman [MSFT}
Gangs
A exception occured when I called the RegisterClientReference(MyClient clientCallback) method.That is:
An unhandled exception of type 'System.Runtime.Serialization.SerializationException' occurred in mscorlib.dll
Additional information: Because of security restrictions, the type System.Runtime.Remoting.ObjRef cannot be accessed.
I had set the TypeFilterLevel to Full,but the exception still occured.
Here is my client code:
string strhost=txthost.Text.Trim();
BinaryServerFormatterSinkProvider serverProvider = new BinaryServerFormatterSinkProvider();
BinaryClientFormatterSinkProvider clientProvider = new BinaryClientFormatterSinkProvider();
serverProvider.TypeFilterLevel = TypeFilterLevel.Full;
IDictionary props = new Hashtable();
props["name"] = "ClientHttp";
props["port"] = 0;
props["typeFilterLevel"] = "Full";
props["rejectRemoteRequests"] = true;
HttpChannel channel = new HttpChannel(props,clientProvider,serverProvider);
ChannelServices.RegisterChannel(channel);
And here is my server code:
BinaryServerFormatterSinkProvider serverProvider = new BinaryServerFormatterSinkProvider();
BinaryClientFormatterSinkProvider clientProvider = new BinaryClientFormatterSinkProvider();
serverProvider.TypeFilterLevel = TypeFilterLevel.Full;
IDictionary props = new Hashtable();
props["port"] = 8180;
props["name"] = "myHttp";
props["typeFilterLevel"] = "Full";
props["rejectRemoteRequests"] = true;
HttpChannel channel = new HttpChannel(props,clientProvider,serverProvider);
ChannelServices.RegisterChannel(channel);
Thanks all people who helped me and concerned my problem.
West
ANeelima
jibotang,
To send messages to your client, you need to open up a channel in your client for input. Depending on the type of channel you are using, there are diffrent ways this should be done. After you've opened up the incoming channel, you can then pass MarshalByRef objects from the client to the server that the server can then call methods on. You can also register for events on the server and receive callbacks that way. Either way, there would need to be some initial call from the client to let the server know about the client (some sort of sign on) After that the server can initiate calls to that client.
--Hoop
[MSFT]