|
-
Dec 22nd, 2005, 10:05 AM
#1
Thread Starter
Lively Member
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.
-
Jan 19th, 2006, 03:24 PM
#2
Hyperactive Member
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.
-
Jan 19th, 2006, 04:38 PM
#3
Thread Starter
Lively Member
Re: problem with net remoting
 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.
-
Feb 16th, 2006, 07:01 AM
#4
New Member
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
-Phil
Microsoft Certified Application Developer
Microsoft Certified Professional
COMPTia Network+
-
Feb 16th, 2006, 07:09 AM
#5
Thread Starter
Lively Member
Re: problem with net remoting
 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.
-
Feb 16th, 2006, 08:12 AM
#6
New Member
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+
-
Feb 16th, 2006, 08:52 AM
#7
Thread Starter
Lively Member
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.
-
Feb 16th, 2006, 02:46 PM
#8
Fanatic Member
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.
-
Feb 17th, 2006, 04:53 AM
#9
Thread Starter
Lively Member
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.
-
Apr 3rd, 2006, 09:41 AM
#10
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|