Enumeration
Indicates the type of error that occurred during a Windows Sockets operation.
Members
-
SuccessNo error occurred.0
-
ConnectionAbortedA connection was forcibly closed by a peer.10053
-
ConnectionRefusedA connection attempt failed because the connected party did not properly respond after a period of time or the established connection was broken.10061
-
HostNotFoundAn underlying network resource or service is not found.11001
-
InvalidArgumentAn invalid argument was supplied to a Windows Sockets API function.10022
-
NetworkDownA socket operation encountered a dead network.10050
-
NetworkUnreachableAn attempt to send data failed because there is no network path to the target host.10051
-
TimedOutA connection attempt failed because the connected party did not properly respond after a period of time.10060
-
WouldBlockA nonblocking socket operation could not be completed immediately.10035
Example Usage
try {
// Attempt to connect to a remote host
Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
client.Connect("nonexistent.domain.invalid", 80);
} catch (SocketException se) {
Console.WriteLine($"Socket error: {se.SocketErrorCode}");
switch (se.SocketErrorCode)
{
case SocketError.ConnectionRefused:
Console.WriteLine("The connection was refused by the target machine.");
break;
case SocketError.TimedOut:
Console.WriteLine("The connection attempt timed out.");
break;
case SocketError.HostNotFound:
Console.WriteLine("The specified host was not found.");
break;
default:
Console.WriteLine($"An unexpected socket error occurred: {se.Message}");
break;
}
}