通常只允许每个套接字地址(协议/网络地址/端口)?我一直在谷歌上搜索一个严肃的解决方案,但我只得到“Regisrty解决方案”的东西,我认为这与我的问题无关。出于某种原因,当我只启动一次TcpListner时出现此错误,如果它失败,我会停止服务器。我真的不明白。这是我的代码:classProgram{privatestaticstringServerName="";私人静态字符串用户名=“”;私人静态字符串密码=“”;私有静态字符串dbConnectionSring="";私有静态X509CertificateadminCertificate;私有静态字节[]readBuffer=新字节[4096];staticvoidMain(string[]args){Console.WriteLine("PleasegrantSQLServeraccesstotheAdminServer:n");Console.Write("服务器名称:");ServerName=Console.ReadLine();Console.Write("n个用户名:");用户名=Console.ReadLine();Console.Write("n密码:");密码=PasswordMasker.Mask(密码);dbConnectionSring=SQLServerAccess.CreateConnection(ServerName,UserName,Password);adminCertificate=Certificate.GenerateOrImportCertificate("AdminCert.pfx","randomPassword");try{Console.WriteLine("正在端口443上的WildCard地址上初始化服务器...");TcpListener监听器=newTcpListener(IPAddress.Any,443);try{Console.WriteLine("开始写10at{0}:443...",IPAddress.Any);//积压设置为最大整数值,但底层网络堆栈会将此值重置为其内部最大值listener.Start(int.MaxValue);Console.WriteLine("Listening...Waitingforaclienttoconnect...");intConnectionCount=0;while(true){try{listener.BeginAcceptTcpClient(newAsyncCallback(AcceptCallback),listener);ConnectionCount++;Console.WriteLine("Acceptedconnection#"+ConnectionCount.ToString());}catch(SocketExceptionerr){Console.WriteLine("Acceptfailed:{0}",err.Message);}}}catch(异常ex){Console.WriteLine("Listeningfailedtostart.");listener.Stop();Console.WriteLine(ex.Message);}}catch(Exceptionex){Console.WriteLine("InitialiazingserverFailed.");.WriteLine(ex.Message);}}非常感谢你的帮助!我打开CMD并输入:netstat-a我查看了本地地址栏我查看了端口部分。我看到程序中的端口是已经在另一个程序中处于活动状态(正在使用中)。我将程序中的端口更改为其他端口。高效的!非常感谢:@DavidSchwartz,@Gusman以上是C#学习教程:通常只允许每个套接字地址(协议/网络地址/端口)?如果所有分享的内容对你有用,需要进一步了解C#学习教程,希望大家多多关注。本文收集自网络,不代表立场。如涉及侵权,请点击右侧联系管理员删除。如需转载请注明出处:
