|
|
Remoting difficulties, sending object on server to client (unrequested) |
|
Author |
Message |
DaveE1

|
Posted: .NET Remoting and Runtime Serialization, Remoting difficulties, sending object on server to client (unrequested) |
Top |
.Net remoting hasn't made me very happy lately X( I have a client and a server that need to send messages back and forth, sometime they are requested, sometimes not. Having a client send/get data from the server is easy. I am having a hell of a time getting data from the server to the clients when they don't ask for it (eg. status updates) I have a server .exe, library .dll, and a client .exe. The majority of my server implementation is in the server .exe, which unbelievably, isn't the norm ! Most of the examples I have seen have the server implemented in the library :\ Furthermore, my server and lib share a namespace whereas my client has its own. I have come across a super fantasic example on c-sharpcorner.com in the article "Remote Objects: Part I" It is a server/client chat program with almost everything I need. The example contains a partial solution to sending unsolicited data from a server to a client. It does it via the following: - a. Make a (marshalbyref) object in the library that is a server activated singleton which fires off events that the client subscribes to.
- b. Make another (marshalbyref) object (this one is abstract) in the library. It has 2 functions, a submission callback and an internal submission callback. The submission callback is implemented and calls the internal submission callback which is protected and abstract.
- c. Have the client implement the internal submission callback function, within a class that inherits from the one in b.
- d. In the client, bind the events from a. to the submission callback in b.
- e. In the server, make the remote object in a. which calls its methods, that fire events in a. which then call (because of the client) the submission callback in b. which then calls the internal submission callback in b. which is implemented by the client in c.
I probably just lost 75% of my readers, but I will continue. The above few steps (however conveluted) DO work.... Until... I monkey with it and try to pass something other than text. The text is passed happily through a RemoteEventArgs : EventArgs type of class that is passed through the events. What I tried is: adding another small object in the library. Then I added a member to the RemoteEventArgs class OF this type. On the server side I make an instance of my new class, I pass it to a method of a remoted object in the library. This object fails in making an instance of my RemoteEventArgs class. Code where it fails: RemoteEventArgs e = new RemoteEventArgs(rServerToClientObj); Exception thrown: "Object reference not set to an instance of an object." Here are my two little classes in the library: [Serializable] public class RemoteEventArgs : EventArgs { public ServerToClientObj reServerToClientObj; public RemoteEventArgs(ServerToClientObj retServerToClientObj) { this.reServerToClientObj.a = retServerToClientObj.a; } } [Serializable] public class ServerToClientObj : EventArgs { public string a; public ServerToClientObj ( string B) { a = A; } } Thanks to all in advance. After re-reading this it seems as though I am breaking some rules when making an instance on the server side and then passing it to a server activated remoted object. This remote object doesn't seem to be able to see my instance. Any ideas on a solution I must sleep now.
.NET Development21
|
|
|
|
 |
DaveE1

|
Posted: .NET Remoting and Runtime Serialization, Remoting difficulties, sending object on server to client (unrequested) |
Top |
[Serializable] public class RemoteEventArgs : EventArgs { public ServerToClientObj reServerToClientObj; public RemoteEventArgs(ServerToClientObj retServerToClientObj) { this.reServerToClientObj.a = retServerToClientObj.a; } } should be: [Serializable] public class RemoteEventArgs : EventArgs { public ServerToClientObj reServerToClientObj; public RemoteEventArgs(ServerToClientObj retServerToClientObj) { this.reServerToClientObj = new ServerToClientObj(retServerToClientObj.a); } } sorry, I guess I shouldn't post with a lack of sleep. At least other people can use the solution that I implemented/borrowed for similar problems. The only problem with this solution is: there might be issues with many clients attached. I have come across an eventrepeater class that you can stuff into the lib which will handle each client seperately so that any exception thrown because of disconnected clients can be handled and the event for that client unsubscribed. Maybe I'll post a link to it if I come across it. The article I mentioned really has a good solution for unsolicited server messages to clients which solves the only big problem that I had with .net remoting.
|
|
|
|
 |
Dave27

|
Posted: .NET Remoting and Runtime Serialization, Remoting difficulties, sending object on server to client (unrequested) |
Top |
I'm currently working on a project, end I have this issue right now. Also, we're new to remoting! Can you explain your solution, do you have a source of a project explaining how to send to clients(in our case it's multiple clients. Thanks. Dave B.
|
|
|
|
 |
|
|