Socket weirdness



See some strange results on Send and peer with a closed Receive. Setup a
test harness. Server accepts socket, then just does a Shutdown.Receive
right away and waits. The client socket does both blocking Sends and
BeginSends to see the difference in behavior.

Results:
1) Using blocking Sends - The first send returns 10, which is the buffer
size. Future Sends, return 0 and no exception. This behavior seems not to
fly with the doco. The send should block until 10 bytes are sent to kernel
mode or throw an exception, *not return 0. Note the socket is in blocking
mode (default setting).

2) Using async BeginSend gives completly different results. The first
EndSend returns 10 as above. The second BeginSend returns a null
IAsyncResult and sets SocketError to "ConnectionReset". I find this
behavior very strange. BeginSend should never return a null IAsyncResult as
that FooBars the async pattern (it should always return IAsync or
exception). It should save the exception for the EndSend call. Second, why
does it set SocketError to ConnectionReset, when blocking Send does not seem
to care. The two behaviors should be consistent.

3) Also, what is the point of SocketError being an out parm? It should just
be included in the SocketException and thrown - no?

TIA

--
William Stacey [MVP]



.



Relevant Pages

  • Re: An existing connection was forcibly closed by the remote host...
    ... EndReceivewill throw "Can't access disposed object" exception whenever the connection is terminated. ... In MS .NET Socket implementation there is no mechanism for the socket object to signal to the main thread that it is about to be disposed. ... public Socket ClientSocket ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: "invalid handle", sockets, threads and garbage collector
    ... your IntPtr value happens to coincide with a reference. ... The exception contains "invalid handle" message. ... Socket constructor problem ... finalization means closing the handle to resource. ...
    (microsoft.public.dotnet.framework.clr)
  • Re: reconnect tcp
    ... instance throws a fatal exception, ... to close the socket and reconnect. ... public ClientHandler(Socket client, int timeout) ... while (rxDataCounter < receiveBytes) ...
    (microsoft.public.dotnet.languages.csharp)
  • "invalid handle", sockets, threads and garbage collector
    ... The exception contains "invalid handle" message. ... Socket constructor problem ... finalization means closing the handle to resource. ...
    (microsoft.public.dotnet.framework.clr)
  • SMTP Virtual Server in IIS V5.1
    ... Exception Details: System.Net.Sockets.SocketException: No connection could ... Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState ... state, IAsyncResult asyncResult, Int32 timeout, Exception& exception) +421 ... System.Web.UI.WebControls.LoginUtil.SendPasswordMail(String email, String ...
    (microsoft.public.windowsxp.general)