Re: Socket.Disconnect Method



Be careful about using that word "bug" - the fact that one is unable to use
something doesn't necessarily imply that it is broken, and may end up making
you look foolish!

According to the documentation for this method, there are 3 distinct
possible exceptions that can be thrown when using this method:

PlatformNotSupportedException
This method requires Windows 2000 or earlier, or the exception will be
thrown.

ObjectDisposedException
The Socket object has been closed.

SocketException
An error occurred when attempting to access the socket. See the Remarks
section for more information.

Here is a more or less complete list of Socket Error Codes and their
meanings:
http://www.sockets.com/err_lst1.htm

It looks to me like the underlying error code could have been:
WSAEINVAL (10022) Invalid argument.

I'm not sure which of the 3 exceptions would have been raised if this were
the case, but the documentation does seem to indicate that this parameter is
not supported on Windows versions after Windows 2000.

Also, there are a few other notes in the documentation that may be relevant:

If you are using a connection-oriented protocol, you can use this method to
close the socket. This method ends the connection and sets the Connected
property to false. However, if reuseSocket is true, you can reuse the
socket.

To ensure that all data is sent and received before the socket is closed,
you should call Shutdown before calling the Disconnect method.

If you need to call Disconnect without first calling Shutdown, you can set
the DontLingerSocket option to false and specify a nonzero time-out interval
to ensure that data queued for outgoing transmission is sent. Disconnect
then blocks until the data is sent or until the specified time-out expires.
If you set DontLinger to false and specify a zero time-out interval, Close
releases the connection and automatically discards outgoing queued data.

Note
If you receive a SocketException, use the SocketException.ErrorCode property
to obtain the specific error code. After you have obtained this code, refer
to the Windows Sockets version 2 API error code documentation in the MSDN
library for a detailed description of the error.

Note
This member outputs trace information when you enable network tracing in
your application. For more information, see Network Tracing.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Chicken Salad Alchemist

I recycle.
I send everything back to the planet it came from.

"C. Coulter" <wizard2277@xxxxxxxxxxx> wrote in message
news:129c5figgr4d0ec@xxxxxxxxxxxxxxxxxxxxx
Hi all!

I'm working on a socket application using synchronous
TCP sockets and the BackGroundWorker control. I would
like to reuse the socket without having to go through
the bother of setting socket options in code. This
is what the Socket.Disconnect(True) method is supposed
to accomplish. However, this method always fails with
an "invalid argument" exception. All the documentation
that I can find indicates that the argument is supposed
to be a Boolean.

Is this a bug in Framework 2.0 and/or VS .Net 2005? If
so, has there been any further word as to when Service
Pack 1 is supposed to come out? They announced SP1
would be out "in the first part of 2006" back in November.

Thanks for your help,

C. Coulter
wizard2277@xxxxxxxxxxxxxxxxx


.



Relevant Pages

  • Re: Socket.Disconnect Method
    ... Although the exception list in the MSDN documentation ... Windows XP SP2. ... An error occurred when attempting to access the socket. ... use the SocketException.ErrorCode property to obtain the specific error code. ...
    (microsoft.public.vsnet.general)
  • Re: Winsock recv() trouble
    ... I keep getting the error code 10057. ... I know this is the Socket is ... but I check to see if there is a socket problem ... > Somehow I lose the connection and I do not know why. ...
    (microsoft.public.vc.language)
  • Re: Socket.Close
    ... > to the internal error code that is causing the exception to be thrown? ... exception being thrown, but rather to a exception not being thrown when it ... connection is ended at the other end or when the socket is closed. ...
    (microsoft.public.dotnet.framework.compactframework)
  • RE: AcceptEx on XP SP2 returning ERROR_NETNAME_DELETED
    ... error code, it means the other end of the socket may has already closed. ... that the server app runs on XP Pro, SP 2 machine, then why do you say "The ... To isolate the problem from VMWare, you may use 2 real machines to test the ...
    (microsoft.public.win32.programmer.networks)
  • Re: Connection broken on recv() function
    ... >>> with the error code WSAECONNRESET. ... it still blocked in the recv() function. ... >>> I don't want to use a nonblock socket. ... On my system whenever I unplug the cable: ...
    (microsoft.public.win32.programmer.kernel)

Loading