Remoting Question
-
I am writing a simple remoting server and have a little problem. everytime I restart the server after it has been used by a client I get the following error. Only one usage of each socket address (protocol/network address/port) is normally permitted If I leave the machine for about 5 minutes then the problem goes away. The server code I am using looks like this...
TcpServerChannel channel = null ; try { channel = new TcpServerChannel (8088) ; ChannelServices.RegisterChannel (channel) ; RemotingConfiguration.RegisterWellKnownServiceType ( typeof (ClassLibrary.Class1), "Hi", WellKnownObjectMode.SingleCall) ; System.Console.WriteLine ("Hit to exit") ; System.Console.ReadLine () ; } catch (System.Exception err) { System.Windows.Forms.MessageBox.Show (err.Message) ; } finally { if (channel != null) { ChannelServices.UnregisterChannel (channel) ; } }
As far as I can tell the unregister Channel always gets called. How do I ensure that the channel is released so it can be reused? Thanks Stephen -
I am writing a simple remoting server and have a little problem. everytime I restart the server after it has been used by a client I get the following error. Only one usage of each socket address (protocol/network address/port) is normally permitted If I leave the machine for about 5 minutes then the problem goes away. The server code I am using looks like this...
TcpServerChannel channel = null ; try { channel = new TcpServerChannel (8088) ; ChannelServices.RegisterChannel (channel) ; RemotingConfiguration.RegisterWellKnownServiceType ( typeof (ClassLibrary.Class1), "Hi", WellKnownObjectMode.SingleCall) ; System.Console.WriteLine ("Hit to exit") ; System.Console.ReadLine () ; } catch (System.Exception err) { System.Windows.Forms.MessageBox.Show (err.Message) ; } finally { if (channel != null) { ChannelServices.UnregisterChannel (channel) ; } }
As far as I can tell the unregister Channel always gets called. How do I ensure that the channel is released so it can be reused? Thanks StephenThe channel should get automatically unregistered when you quit the application. Since any port that your process is listening on will be closed when your process terminates. You say that the problem only occurs after a client has used it, does the problem occur if a client dosen't use it and you restart the server?. If that is the case then the probably lies with the client somehow. Maybe you can post the relevant client code as well. I had a similar problem once but it was on the Client side, the problem there was that i was showing a messagebox and forgot to close it thus the application never completely terminated and the port remained open. May the Source be with you Sonork ID 100.9997 sijinjoseph
-
The channel should get automatically unregistered when you quit the application. Since any port that your process is listening on will be closed when your process terminates. You say that the problem only occurs after a client has used it, does the problem occur if a client dosen't use it and you restart the server?. If that is the case then the probably lies with the client somehow. Maybe you can post the relevant client code as well. I had a similar problem once but it was on the Client side, the problem there was that i was showing a messagebox and forgot to close it thus the application never completely terminated and the port remained open. May the Source be with you Sonork ID 100.9997 sijinjoseph
Thanks for the reply, If I just start and stop the server I have no problems, the server will restart without the error. Its only if a client has connected that the server has a problem. Both the Client and server are simple c# console apps. The client code I am using for this test looks like this..
ChannelServices.RegisterChannel (new TcpClientChannel ()) ; ClassLibrary.Class1 = (ClassLibrary.Class1 )Activator.GetObject ( typeof (ClassLibrary.Class1), "tcp://localhost:8088/Hi") ; for (int i = 0 ; i < 5 ; i++) { Console.WriteLine (hello.Greeting ("Stephen")) ; }
and the remoted object looks like thispublic class Class1: System.MarshalByRefObject { public string Greeting (string name) { return "Completed" ; } }
Both the client and the server fully terminate (i.e. debuger returns and nothing in process list) before I attempt to restart the server. Thanks Stephen. -
Thanks for the reply, If I just start and stop the server I have no problems, the server will restart without the error. Its only if a client has connected that the server has a problem. Both the Client and server are simple c# console apps. The client code I am using for this test looks like this..
ChannelServices.RegisterChannel (new TcpClientChannel ()) ; ClassLibrary.Class1 = (ClassLibrary.Class1 )Activator.GetObject ( typeof (ClassLibrary.Class1), "tcp://localhost:8088/Hi") ; for (int i = 0 ; i < 5 ; i++) { Console.WriteLine (hello.Greeting ("Stephen")) ; }
and the remoted object looks like thispublic class Class1: System.MarshalByRefObject { public string Greeting (string name) { return "Completed" ; } }
Both the client and the server fully terminate (i.e. debuger returns and nothing in process list) before I attempt to restart the server. Thanks Stephen.Not having any luck with this problem, so I downloaded TCPView from sysinternals.com. Now I can see the server program start and open two ports. The first is different every time and counts up from about 4010 (the lowest I have seen yet) and the port I am intreased in 8088. The clients connect and all is well. I then close the server and I see ports close in TCPView. I restart the server and I see the ports reopened and attached to the new server process. Then I get the message Only one usage of each socket address (protocol/network address/port) is normally permitted WTF, the ports _where_ opened ok? It fails on this line of code
channel = new TcpServerChannel (8088) ;
This is the stack trace at System.Runtime.Remoting.Channels.Tcp.TcpServerChannel.StartListening(Object data) at System.Runtime.Remoting.Channels.Tcp.TcpServerChannel.SetupChannel() at System.Runtime.Remoting.Channels.Tcp.TcpServerChannel..ctor(Int32 port) at Server.Server.Main(String[] args) in d:\devwork.net\experimentation\remoting\server\server.cs:line 22 If I sit and watch TCPView for five minutes I do not see any ports closing in that period, but the project works again, only the once, after that delay So I am at a loss now, Don't really know where to go from here, anyone, any ideas? Anyone know of any good books or articles on remoting? Thanks Stephen -
Thanks for the reply, If I just start and stop the server I have no problems, the server will restart without the error. Its only if a client has connected that the server has a problem. Both the Client and server are simple c# console apps. The client code I am using for this test looks like this..
ChannelServices.RegisterChannel (new TcpClientChannel ()) ; ClassLibrary.Class1 = (ClassLibrary.Class1 )Activator.GetObject ( typeof (ClassLibrary.Class1), "tcp://localhost:8088/Hi") ; for (int i = 0 ; i < 5 ; i++) { Console.WriteLine (hello.Greeting ("Stephen")) ; }
and the remoted object looks like thispublic class Class1: System.MarshalByRefObject { public string Greeting (string name) { return "Completed" ; } }
Both the client and the server fully terminate (i.e. debuger returns and nothing in process list) before I attempt to restart the server. Thanks Stephen.First of all can you also post the server remoting code. Your code seems perfectly allright. Maybe you can use Tracking Services to see what is really going on on the server side. That should be more helpful than using TCPView. Have you checked Task Manager after closing your server to make sure that it's not running. Your problem is very strange indeed. May the Source be with you Sonork ID 100.9997 sijinjoseph
-
First of all can you also post the server remoting code. Your code seems perfectly allright. Maybe you can use Tracking Services to see what is really going on on the server side. That should be more helpful than using TCPView. Have you checked Task Manager after closing your server to make sure that it's not running. Your problem is very strange indeed. May the Source be with you Sonork ID 100.9997 sijinjoseph
I think I have found the cause of the problem. I have the Winsock Proxy Client installed on this machine that lets me connect to the Internet via an ISA server. If I disable the client the problem goes away. This only seemes to affect servers written in dotnet. I think I will have a look at the tracking services to see if I can find out more detail on why it is going wrong. Stephen.