Link to home
Start Free TrialLog in
Avatar of gustierng
gustierng

asked on

close connection to server (.net remoting)

How do I close a client connection to a server so that others can use it?

This is using .net remoting, so the ChannelServices.RegisterChannel to setup the channel and Activator.GetObject used to create a connection to the shared port.

Thank you
Avatar of Anurag Thakur
Anurag Thakur
Flag of India image

i dont really understand the question in first place.... close the .net remoting connection
this connection is not the same as sql connection
and secondly when the connection means the clinet object goes out of scope or has completed its processing it just releases its memory

are you getting any kinds of errors due to this on .net remoting
Avatar of gustierng
gustierng

ASKER

yes. nothing related to databases.  So does unregistering a channel effectively close the connection by making the port available to other users?
in remoting the port is not used by one connection so there is no point of thinking that once one client is accessing a remoting object other objects cannot access them
secondly you might want to limit the lifetime of the objects created on the server to make optimal use of memoru
and when objects go out of scope the memory as well as connection will be disposed by the garbage collector so you dont have to code an extra step of unregistering the ports
My main problem at the moment is a RemotingException

https://www.experts-exchange.com/questions/24175257/RemotingException.html
Hi
I followed your advice but now I am getting a SocketException:

I start up the server which is updated in realtime on a single port.   Users read data on a second port.  The first time I run the client it works fine.  If I close the app and run the client again I get:

SocketException:
No connection could be made because the target machine actively refused it

I have not even got to the stage of testing multiple users over this port.  I am using a singleton, tcp.

first time the remoting channel is registered correctly and everything runs correctly
but when you run the client second time the previous channel/port to which the registered does not allow you to register it again

you will have to find a way to deregister the port and then regiester it again
that's a good idea, i'll try bthat and let you know.

What if other users are using that port?
actually its not that port
you dont close the port its the channel that you register on the client machine
port/socket on the server is not affected
ok,  so is there a way to refer to a channel by port rather than name?

TcpChannel tcpChannel;
tcpChannel = (TcpChannel)ChannelServices.GetChannel(theChannelName)
if (tcpChannel!= null)
{
      ChannelServices.UnregisterChannel(tcpChannel);
}

Or, is this the way it iss done?
havent used this in .net 20 or above so cannot say this
sorry
how do you close the channel?
that is the same way I have posted above.  You need to check the channel exists
ASKER CERTIFIED SOLUTION
Avatar of Anurag Thakur
Anurag Thakur
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial