Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Get remote object and respond to an event

Get remote object and respond to an event

Scheduled Pinned Locked Moved C#
sysadminhelptutorial
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    wzrd
    wrote on last edited by
    #1

    I'm currently trying to get a remote object, using Remoting... I can get the object, but I can't grab a event the object fires. This is all example code and I just can't seem to get it work. I get the object, but the remote object doesn't see the client sign up to watch for the event, so it never fires the event. Or if you have a better way for my Server and Client to communicate, don't hesitate to share. Any help with would greatly appreciated. If you have more questions, please email me. [Server] using System; using System.Runtime.Remoting; using System.Runtime.Remoting.Channels; using System.Runtime.Remoting.Channels.Tcp; namespace Test.Remote { /// /// Summary description for Class1. /// class Server { static void Main(string[] args) { TcpServerChannel channel = new TcpServerChannel(8086); ChannelServices.RegisterChannel(channel); RemotingConfiguration.RegisterWellKnownServiceType(typeof(RemoteObject), "Hi", WellKnownObjectMode.SingleCall); Console.WriteLine("Hit to exit"); Console.ReadLine(); } } } [Client] using System; using System.Runtime.Remoting.Channels; using System.Runtime.Remoting.Channels.Tcp; namespace Test.Remote { /// /// Summary description for Class1. /// class Client { [STAThread] static void Main(string[] args) { //RemotingConfiguration.Configure("Client.exe.config"); ChannelServices.RegisterChannel(new TcpClientChannel()); RemoteObject obj = (RemoteObject)Activator.GetObject(typeof(RemoteObject), "tcp://localhost:8086/Hi"); EventSink sink = new EventSink(); // register client sink in server - subscribe to event obj.Status += new StatusEvent(sink.StatusHandler); obj.LongWorking(5000); // unsubscribe to event obj.Status -= new StatusEvent(sink.StatusHandler); obj.LongWorking(5000); Console.WriteLine("Hit to exit"); Console.ReadLine(); } } } [RemoteObject] using System; namespace Test.Remote { [Serializable] public class StatusEventArgs { public StatusEventArgs(string m) { message = m; } public string Message { get { return message; } set { message = value; } } private string message; } public delegate void StatusEvent(object sender, StatusEventArgs e); /// /// Summary description for Class1. /// public class RemoteObject : MarshalByRefObject { public RemoteObject() { Console.WriteLine("RemoteObject constructor called"); } public event StatusEvent Status; public void LongWorking(int ms) { Console.W

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups