CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: remoting ?

  1. #1
    Join Date
    Jan 2004
    Location
    Germany
    Posts
    7

    remoting ?

    hi i have some problems to realize remoting in C#
    i have an application A on pc1 and i have a application B on pc2
    app A sould start app B (but this is not so important for the beginning)
    app B should sometimes performes the function write(string text) (<- this should be a function from the marshaled class, isn't it?)
    then in app B this text should be added in a textbox

    i tried this the whole day but i wont get it work
    i also tried to realize it only on one machine first and starting A and B manuell, but i get it work neither

    can someone can help plz how to realize this?

  2. #2
    Join Date
    Jan 2004
    Location
    Germany
    Posts
    7
    hi again
    i get it almost but i still have a problem
    i dont know how how to access in the remoteclass the richtextbox in the dialog
    i tried a few ways but i dont get it
    perhaps i realized the whole thing in the wrong way?!
    here is my code - it would be nice if someone can take it look at it

    this is my shared dll:

    namespace LoggerLib
    {
    public interface ILogger
    {
    void Write(string message);
    }
    }




    my remote object (used in the logger (app B)):

    namespace Logger
    {
    public class Logger : MarshalByRefObject, ILogger
    {
    public Logger()
    {
    }

    public RichTextBox rtb = new RichTextBox();

    public void SetRTB(ref RichTextBox rtb)
    {
    this.rtb = rtb;
    }

    public void Write(string message)
    {
    rtb.Text+=message+"\n";
    }
    }
    }



    the dialog of the logger:

    namespace Logger
    public class DlgLogger : System.Windows.Forms.Form
    {
    private System.Windows.Forms.RichTextBox richTextBox1;
    private System.ComponentModel.Container components = null;

    public DlgLogger()
    {
    InitializeComponent();

    TcpServerChannel channel = new TcpServerChannel(1234);
    ChannelServices.RegisterChannel(channel);
    RemotingConfiguration.RegisterWellKnownServiceType
    (typeof(Logger), "logging.rem", WellKnownObjectMode.SingleCall);
    logger = new Logger();
    logger.SetRTB(ref this.richTextBox1);
    }

    Logger logger;

    ... generated code ...

    public void AddRichText(string text)
    {
    this.richTextBox1.Text += text+"\n";
    }
    }
    }




    and my app A that "sends" the log text:

    namespace App
    public class DlgApp : System.Windows.Forms.Form
    {
    private System.Windows.Forms.Button button1;
    private System.ComponentModel.Container components = null;

    public DlgApp()
    {
    InitializeComponent();

    ilogger = (ILogger) Activator.GetObject(typeof(ILogger), "tcp://localhost:1234/logging.rem");
    }

    ILogger ilogger;

    ... some code ...

    private void button1_Click(object sender, System.EventArgs e)
    {
    ilogger.Write("Test");
    }
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured