Results 1 to 10 of 10

Thread: problem with net remoting

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2003
    Posts
    89

    problem with net remoting

    hello, I have followed a tutorial on how to expose a class method over the net using net remoting.

    All is working fine. I have 2 apps, one acting as a server:
    Code:
    TcpChannel channel = new TcpChannel(12345);
    ChannelServices.RegisterChannel(channel);
    RemotingConfiguration.RegisterWellKnownServiceType( 
             typeof(myclass), 
             "mymethod", 
             WellKnownObjectMode.Singleton );
    and the other acting as a client:
    Code:
    TcpChannel chan = new TcpChannel();
    ChannelServices.RegisterChannel(chan);
    obj = (myclass) Activator.GetObject( 
             typeof(myclass),
             "tcp://localhost:12345/mymethod" );
    I then tried to combine this two snippets into a single chat application. I wanted to run two instances of it and let them both act as client and server at the same time.
    InstanceA calls mymethod on InstanceB
    InstanceB calls mymethod on InstanceA
    Unfortunately I get an error when I try to register the client channel after I registered the server channel. ie I get an error on the line in red:

    Code:
    TcpChannel channel = new TcpChannel(12345);
    ChannelServices.RegisterChannel(channel);
    RemotingConfiguration.RegisterWellKnownServiceType( 
             typeof(myclass), 
             "mymethod", 
             WellKnownObjectMode.Singleton );
    
    TcpChannel chan = new TcpChannel();
    ChannelServices.RegisterChannel(chan);
    obj = (myclass) Activator.GetObject( 
             typeof(myclass),
             "tcp://localhost:12345/mymethod" );
    what should I do? Is what I'm trying to do possibile in first place?
    I cannot provide the exception description because the debugger just says "Application has generated an exception that could not be handled".
    Many thanks in advance ^^
    Last edited by BrightSoul; Dec 22nd, 2005 at 10:10 AM.
    - mo! I said MOOOOOOO!!
    - ...yep, that's a cow, alright.

  2. #2
    Hyperactive Member
    Join Date
    May 2001
    Posts
    306

    Re: problem with net remoting

    i'm guess that your problem is you are registering the channel port, 12345, twice and it doesn't like it.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jun 2003
    Posts
    89

    Re: problem with net remoting

    Quote Originally Posted by scostell
    i'm guess that your problem is you are registering the channel port, 12345, twice and it doesn't like it.
    Well thanks, but I'm not passing any argument to the TcpChannel constructor the second time This is because it's the client part and it doesn't need to open any port.

    TcpChannel chan = new TcpChannel();
    ChannelServices.RegisterChannel(chan);

    am I missing something?
    - mo! I said MOOOOOOO!!
    - ...yep, that's a cow, alright.

  4. #4
    New Member
    Join Date
    Sep 2004
    Posts
    15

    Re: problem with net remoting

    You only need the last three lines of code in the client-side app

    VB Code:
    1. TcpChannel chan = new TcpChannel();
    2. ChannelServices.RegisterChannel(chan);
    3. obj = (myclass) Activator.GetObject(
    4.          typeof(myclass),
    5.          "tcp://localhost:12345/mymethod" );

    Take a look at this tutorial if you need more help

    http://www.developer.com/net/cplus/a...0919_1479761_1
    -Phil


    Microsoft Certified Application Developer
    Microsoft Certified Professional
    COMPTia Network+

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jun 2003
    Posts
    89

    Re: problem with net remoting

    Quote Originally Posted by phibud
    You only need the last three lines of code in the client-side app
    yes, and it IS working if I build two apps, one acting as a client and one acting as a server.

    But what I'm trying to accomplish now is a single app that acts BOTH as server and as a client. So what I did was combining both pieces of code into a single app, is it possible to make it work?
    - mo! I said MOOOOOOO!!
    - ...yep, that's a cow, alright.

  6. #6
    New Member
    Join Date
    Sep 2004
    Posts
    15

    Re: problem with net remoting

    I'm sorry for misunderstanding you, I tried doing it and I couldnt do it either. But why would you really want to do this? Doesn't it take the remoting part out of remoting?
    -Phil


    Microsoft Certified Application Developer
    Microsoft Certified Professional
    COMPTia Network+

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Jun 2003
    Posts
    89

    Re: problem with net remoting

    Doesn't it take the remoting part out of remoting?
    why exactly? Imagine I want to code a peer-to-peer chat application, can I do that with .net remoting?
    - mo! I said MOOOOOOO!!
    - ...yep, that's a cow, alright.

  8. #8
    Fanatic Member
    Join Date
    May 2001
    Posts
    837

    Re: problem with net remoting

    Are you running two instances of the app on the same computer or just one?
    The human brain cannot hold all of the knowledge that exists in this world, but it can hold pointers to that knowledge.

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Jun 2003
    Posts
    89

    Re: problem with net remoting

    I can't get the first instance to work. When I launch it, I get that error.
    Last edited by BrightSoul; Feb 17th, 2006 at 05:07 AM.
    - mo! I said MOOOOOOO!!
    - ...yep, that's a cow, alright.

  10. #10
    Fanatic Member alexandros's Avatar
    Join Date
    Oct 2002
    Location
    Milky Way Galaxy
    Posts
    694

    Re: problem with net remoting

    i think that you have to register a tcp channel only once for each machine no matter how many instances of the client you are going to make.
    so delete this part :
    TcpChannel chan = new TcpChannel();
    ChannelServices.RegisterChannel(chan);

    and use the first channel to get the second object.

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