Set SocketOptionName.ReuseAddress given a TcpChannel object.


Douglas Peterson

I'm using Remoting to implement a client/server. I recently discovered that
I cannot connect a second instance client because it is trying to reuse the
port and appearently the socket isn't setup for address reuse. Upon creating
the TcpChannel I get the following exception:
"An unhandled exception of type 'System.Net.Sockets.SocketException'
occurred in system.runtime.remoting.dll
Additional information: Only one usage of each socket address
(protocol/network address/port) is normally permitted"

The channel is created like this:

BinaryServerFormatterSinkProvider provider = new
provider.TypeFilterLevel = TypeFilterLevel.Full;
IDictionary props = new Hashtable();
props["port"] = 8081;
TcpChannel channel = new TcpChannel(props, null, provider);

Now I can't figure out how to gain access to the Socket object so I can call
SetSocketOption on it.

I tried adding
props["exclusiveAddressUse"] = false;
but I don't think that's the same thing as the ReuseAddress socket option
(it didn't work).

If I don't specify a port to the TcpChannel constructor, it only makes a
one-way connection (i.e. the remotable object cannot callback the clients).

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question