Preventing Exception thrown: 'System.Net.Sockets.SocketException' in System.dll










1















This one has been causing me some bother for a while. I have a TcpClient that runs on a thread and trys to connect to the client



 client = new TcpClient();
client.Connect(m_Hostname, m_PortNum);


On failure the Connect function throws a SocketException if it cannot connect. Then after say, 10 seconds, it attempts to reconnect. The target client is basically has a listener socket that is only active periodically so it will attempt to reconnect to the target client throughout the lifetime of the program.



The problem is that the message Exception thrown: 'System.Net.Sockets.SocketException' in System.dll is spat out to the debugger every 10 seconds, each time it cannot connect. It seems there is no real way to prevent this from happening. I thought I could potentially check if the target machine is available first before connecting but I cant see this anywhere.



It seems bad to control program flow using exceptions but I am not sure of another way; worst case I'd like to prevent the exception from printing out in the debugger because it causes unnecessary spam.










share|improve this question






















  • could you use UDP instead. DO you own the other end?

    – pm100
    Nov 15 '18 at 16:14












  • Yes it needs to be 100% reliable though

    – Asheh
    Nov 15 '18 at 16:15











  • you can layer reliable on top of UDP by sending a message and timeing out on th response. (TCP is build on IP , which is basically UDP) Or you can use a UDP exchange to see if the server is up then open a tcp connection

    – pm100
    Nov 15 '18 at 16:22












  • The issue is, if you did do a check prior to connecting, it can still fail, because networking is unpredictable. If your issue is that the message is printed then I'm not sure you should/could solve it programatically.

    – Default
    Nov 15 '18 at 17:03






  • 1





    Possible duplicate of Visual Studio - suppress certain "Exception thrown" messages

    – Default
    Nov 15 '18 at 17:09















1















This one has been causing me some bother for a while. I have a TcpClient that runs on a thread and trys to connect to the client



 client = new TcpClient();
client.Connect(m_Hostname, m_PortNum);


On failure the Connect function throws a SocketException if it cannot connect. Then after say, 10 seconds, it attempts to reconnect. The target client is basically has a listener socket that is only active periodically so it will attempt to reconnect to the target client throughout the lifetime of the program.



The problem is that the message Exception thrown: 'System.Net.Sockets.SocketException' in System.dll is spat out to the debugger every 10 seconds, each time it cannot connect. It seems there is no real way to prevent this from happening. I thought I could potentially check if the target machine is available first before connecting but I cant see this anywhere.



It seems bad to control program flow using exceptions but I am not sure of another way; worst case I'd like to prevent the exception from printing out in the debugger because it causes unnecessary spam.










share|improve this question






















  • could you use UDP instead. DO you own the other end?

    – pm100
    Nov 15 '18 at 16:14












  • Yes it needs to be 100% reliable though

    – Asheh
    Nov 15 '18 at 16:15











  • you can layer reliable on top of UDP by sending a message and timeing out on th response. (TCP is build on IP , which is basically UDP) Or you can use a UDP exchange to see if the server is up then open a tcp connection

    – pm100
    Nov 15 '18 at 16:22












  • The issue is, if you did do a check prior to connecting, it can still fail, because networking is unpredictable. If your issue is that the message is printed then I'm not sure you should/could solve it programatically.

    – Default
    Nov 15 '18 at 17:03






  • 1





    Possible duplicate of Visual Studio - suppress certain "Exception thrown" messages

    – Default
    Nov 15 '18 at 17:09













1












1








1








This one has been causing me some bother for a while. I have a TcpClient that runs on a thread and trys to connect to the client



 client = new TcpClient();
client.Connect(m_Hostname, m_PortNum);


On failure the Connect function throws a SocketException if it cannot connect. Then after say, 10 seconds, it attempts to reconnect. The target client is basically has a listener socket that is only active periodically so it will attempt to reconnect to the target client throughout the lifetime of the program.



The problem is that the message Exception thrown: 'System.Net.Sockets.SocketException' in System.dll is spat out to the debugger every 10 seconds, each time it cannot connect. It seems there is no real way to prevent this from happening. I thought I could potentially check if the target machine is available first before connecting but I cant see this anywhere.



It seems bad to control program flow using exceptions but I am not sure of another way; worst case I'd like to prevent the exception from printing out in the debugger because it causes unnecessary spam.










share|improve this question














This one has been causing me some bother for a while. I have a TcpClient that runs on a thread and trys to connect to the client



 client = new TcpClient();
client.Connect(m_Hostname, m_PortNum);


On failure the Connect function throws a SocketException if it cannot connect. Then after say, 10 seconds, it attempts to reconnect. The target client is basically has a listener socket that is only active periodically so it will attempt to reconnect to the target client throughout the lifetime of the program.



The problem is that the message Exception thrown: 'System.Net.Sockets.SocketException' in System.dll is spat out to the debugger every 10 seconds, each time it cannot connect. It seems there is no real way to prevent this from happening. I thought I could potentially check if the target machine is available first before connecting but I cant see this anywhere.



It seems bad to control program flow using exceptions but I am not sure of another way; worst case I'd like to prevent the exception from printing out in the debugger because it causes unnecessary spam.







c# .net networking tcpclient






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 15 '18 at 16:08









AshehAsheh

829820




829820












  • could you use UDP instead. DO you own the other end?

    – pm100
    Nov 15 '18 at 16:14












  • Yes it needs to be 100% reliable though

    – Asheh
    Nov 15 '18 at 16:15











  • you can layer reliable on top of UDP by sending a message and timeing out on th response. (TCP is build on IP , which is basically UDP) Or you can use a UDP exchange to see if the server is up then open a tcp connection

    – pm100
    Nov 15 '18 at 16:22












  • The issue is, if you did do a check prior to connecting, it can still fail, because networking is unpredictable. If your issue is that the message is printed then I'm not sure you should/could solve it programatically.

    – Default
    Nov 15 '18 at 17:03






  • 1





    Possible duplicate of Visual Studio - suppress certain "Exception thrown" messages

    – Default
    Nov 15 '18 at 17:09

















  • could you use UDP instead. DO you own the other end?

    – pm100
    Nov 15 '18 at 16:14












  • Yes it needs to be 100% reliable though

    – Asheh
    Nov 15 '18 at 16:15











  • you can layer reliable on top of UDP by sending a message and timeing out on th response. (TCP is build on IP , which is basically UDP) Or you can use a UDP exchange to see if the server is up then open a tcp connection

    – pm100
    Nov 15 '18 at 16:22












  • The issue is, if you did do a check prior to connecting, it can still fail, because networking is unpredictable. If your issue is that the message is printed then I'm not sure you should/could solve it programatically.

    – Default
    Nov 15 '18 at 17:03






  • 1





    Possible duplicate of Visual Studio - suppress certain "Exception thrown" messages

    – Default
    Nov 15 '18 at 17:09
















could you use UDP instead. DO you own the other end?

– pm100
Nov 15 '18 at 16:14






could you use UDP instead. DO you own the other end?

– pm100
Nov 15 '18 at 16:14














Yes it needs to be 100% reliable though

– Asheh
Nov 15 '18 at 16:15





Yes it needs to be 100% reliable though

– Asheh
Nov 15 '18 at 16:15













you can layer reliable on top of UDP by sending a message and timeing out on th response. (TCP is build on IP , which is basically UDP) Or you can use a UDP exchange to see if the server is up then open a tcp connection

– pm100
Nov 15 '18 at 16:22






you can layer reliable on top of UDP by sending a message and timeing out on th response. (TCP is build on IP , which is basically UDP) Or you can use a UDP exchange to see if the server is up then open a tcp connection

– pm100
Nov 15 '18 at 16:22














The issue is, if you did do a check prior to connecting, it can still fail, because networking is unpredictable. If your issue is that the message is printed then I'm not sure you should/could solve it programatically.

– Default
Nov 15 '18 at 17:03





The issue is, if you did do a check prior to connecting, it can still fail, because networking is unpredictable. If your issue is that the message is printed then I'm not sure you should/could solve it programatically.

– Default
Nov 15 '18 at 17:03




1




1





Possible duplicate of Visual Studio - suppress certain "Exception thrown" messages

– Default
Nov 15 '18 at 17:09





Possible duplicate of Visual Studio - suppress certain "Exception thrown" messages

– Default
Nov 15 '18 at 17:09












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53323486%2fpreventing-exception-thrown-system-net-sockets-socketexception-in-system-dll%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53323486%2fpreventing-exception-thrown-system-net-sockets-socketexception-in-system-dll%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

What does pagestruct do in Eviews?

Dutch intervention in Lombok and Karangasem

Channel Islands