I used a component for creating socket connection. Now, I have a client and server that can connect to each other by the component. but my problem is it: When some error happening, I got a msg like this:
System.Net.Sockets.SocketException (0x80004005): No connection could be made because the target machine actively refused it
I want to know is any relation between this code (0x80004005) and Winsock Error Codes in MSDN WebSite ? what is this code mean? is it display the value error code?! or something like this?
actually I want to get the related value like 10061
but I dont know how I can get it by above string value. Thanks for any helping.
The ErrorCode property of the exception object contains the socket error code. The list of error codes are defined here.
The error in your case is WSAECONNREFUSED 10061
BTW, you have to catch the SocketException and not the general Exception to get the error code.
try
{
}
catch (System.Net.Sockets.SocketException sockEx)
{
int errorCode = sockEx.ErrorCode;
}
If, however, you want to get the native error code, you can use sockEx.NativeErrorCode
instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With