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 ^^
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.
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 :confused: 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?
Re: problem with net remoting
You only need the last three lines of code in the client-side app
VB Code:
TcpChannel chan = new TcpChannel();
ChannelServices.RegisterChannel(chan);
obj = (myclass) Activator.GetObject(
typeof(myclass),
"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
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?
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? :)
Re: problem with net remoting
Quote:
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?
Re: problem with net remoting
Are you running two instances of the app on the same computer or just one?
Re: problem with net remoting
I can't get the first instance to work. When I launch it, I get that error.
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.