Greetings, I am trying to find a way to decouple a socket from a specific IP / Port combination. My pseudo code is as follows:
ClassA a = new ClassA();
At this point .Net tells me that I already have a socket bound to 127.0.0.1:4567, which is technically true. But no matter what code I insert into the ClassA destructor, or no matter what functions I call on the socket (I tried .Close () and .Disconnect (true)), the socket remains proudly tied to 127.0.0.1:4567 . What can I do to not bind a socket?
EDIT: I do not rely solely on garbage collection (although I also tried this approach). I tried calling a.Close () or a.Disconnect () and only then instantiated aa; this does not solve the problem.
EDIT: I also tried to implement IDisposable, but the code never got it without my method call (which was equivalent to earlier attempts, as the method would just try .Close and .Disconnect). Let me try calling. Ask directly and get back to you.
EDIT (many corrections, apologies): the implementation of IDisposable and the call to the .Dispose () function, from where "a" loses its scope, does not work. My Dispose implementation should still call either. Close, or .Disconnect (true) (or .Shutdown (Both)), but none of them untie the socket.
Any help would be appreciated!
source share