1

To the moment, I found that if host name is invalid, I get Exception with HResult=-2147013895 and If the host name is OK but it refuses the connection attempt, I'm getting System.Runtime.InteropServices.COMException with HResult=-2147014835. No InnerException is available. Because exception types are pretty generic, I'll have to catch Exception, analyse HResult and rethrow if this exception is not specific to network issues. Seems I need to find out which HResult codes to process in my code (all network-related) and re-throw anything else (out of memory and so on).

Is there any list of HResult codes which are specific to network issues? Or maybe there is another, better way to distinguish between network-specific and general exceptions which can be thrown during StreamSocket.ConnectAsync call?

Alex
  • 2,469
  • 3
  • 28
  • 61
  • Are you using same pc , to connect the server or client ? – Vinoth Rajendran Dec 14 '16 at 10:45
  • My client and server are different machines now (I connect to an external host) but they can be the same machine as well. – Alex Dec 14 '16 at 11:39
  • Socket communcation : UWP application it wont work in same pc, it should be different pc – Vinoth Rajendran Dec 14 '16 at 12:28
  • Sorry, I could not understand your comment. – Alex Dec 14 '16 at 12:29
  • 3
    https://msdn.microsoft.com/en-us/windows/uwp/networking/sockets?f=255&MSPPError=-2147217396 . Check the Note section – Vinoth Rajendran Dec 14 '16 at 12:37
  • This helps a bit although it's not clear how I can understand "now it's a socket error and I should process it in my code" or "it's not network error, it's something else and I should re-throw this exception to the caller". – Alex Dec 14 '16 at 12:42
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/130604/discussion-between-vinoth-rajendran-and-alex). – Vinoth Rajendran Dec 14 '16 at 12:46

1 Answers1

0

Have a look here, but if the error code isn't listed you are out of luck.

-2147014835 gives me

WSAECONNREFUSED (wrapped)
No connection could be made because the target machine actively refused it.

-2147013895 gives me

WSAHOST_NOT_FOUND (wrapped)
No such host is known.

Further error codes can be listed here, but I included yours here. Perhaps you find a dedicated list for network and general exceptions, but that should give you a start.

testing
  • 19,681
  • 50
  • 236
  • 417