c# - TcpClient connecting to unavailable service -
so far code have
`tcpclient = new tcpclient(); tcpclient.connect(ip.ipaddress, convert.toint32(ip.port)); if (tcpclient.connected) { console.writeline("host up"); console.readkey(); } else { updatedowntime(ip); }`
the ipaddress , port testing dev site running through iis. have stopped apppool site. if navigate through browser
service unavailable
http error 503. service unavailable.
but if run code connects , prints "host up"
please inform missing in step.
adding in case running same problem. solution after using link in comment above.
foreach (var ip in ipaddresslist) { httpwebresponse myhttpwebresponse = null; seek { var myuri = new uri(ip.url); // create 'httpwebrequest' object specified url. var myhttpwebrequest = (httpwebrequest)webrequest.create(myuri); // set user agent if web browser myhttpwebrequest.useragent = @"mozilla/5.0 (windows; u; windows nt 5.1; en-us; rv:1.8.0.4) gecko/20060508 firefox/1.5.0.4"; myhttpwebresponse = (httpwebresponse)myhttpwebrequest.getresponse(); // release resources of response object. myhttpwebresponse.close(); } grab (webexception ex) { // if here, port not open, or host not reachable updatedowntime(ip, ex.message); } { if (myhttpwebresponse != null) { myhttpwebresponse.close(); } } }
inside updatedowntime(), load service results database when url not accessible can reported on , task scheduler task created run every 5 minutes. sends email when service down. tells service went down, when , response error.
my end result using ssrs create study whenever executives need know metrics on multiple different scenarios of when things went down, how long, if downwards during prime hours, etc., etc.
hope helps else if find same issue.
c# tcpclient uptime-monitoring
No comments:
Post a Comment