c# - I am getting error code 10061 when I try to check the availability of Port -
i trying find port availability of below c# code, , getting exception "error code 10061: connection refused " need in solving issue. ports open shown closed facing porblem
class program { private string _hosturi; private static bool m_blniswinauth = false; static void main(string[] args) { hostname tcp; bool udp = false; program pr = new program(); tcp = pr.getportavability("127.0.0.1", 80, true); console.writeline(tcp); console.readline(); } public hostname getportavability(string _hosturi, int _portnumber, bool istcp) { hostname returnvalue = new hostname(); returnvalue.hostname = _hosturi; returnvalue.result = false; ipaddress ipa = (ipaddress)dns.gethostaddresses(_hosturi)[0]; try { socket sock; if (istcp) sock = new socket(addressfamily.internetwork, sockettype.stream, protocoltype.tcp); else sock = new socket(addressfamily.internetwork, sockettype.dgram, protocoltype.udp); sock.connect(ipa, _portnumber); if (sock.connected) returnvalue.result = true; else returnvalue.result = false; sock.close(); } catch (socketexception se) { if (se.errorcode == 10061) returnvalue.result = true; else returnvalue.result = false; } catch (exception e) { returnvalue.result = false; } return returnvalue; } }
error 10061 connection refused server
makes sense me because trying connect socket given ip address , port number. there no other socket waiting connection.
need find different way. 'endpoint'.
Comments
Post a Comment