通常每个套接字地址(协议/网络地址/端口)只允许使用一次? [英] Only one usage of each socket address (protocol/network address/port) is normally permitted?

查看:56
本文介绍了通常每个套接字地址(协议/网络地址/端口)只允许使用一次?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在 google 上寻找一个严肃的解决方案,但我只得到了注册解决方案"之类的东西,我认为这与我的问题无关.

I've been looking for a serious solution on google and i only get "Regisrty solutions" kind of stuff which i don't think even relate to my problem.

出于某种原因,我收到此错误,而我只启动了一次 TcpListner,并且当 + 如果失败时我会停止服务器.我真的不明白.这是我的代码:

For some reason i get this Error, while i'm only starting the TcpListner once, and when+if fails i stop the server. I really don't get it. Here is my code:

class Program
    {
        private static string ServerName = "";
        private static string UserName = "";
        private static string Password = "";
        private static string dbConnectionSring = "";
        private static X509Certificate adminCertificate;
        private  static byte[] readBuffer = new byte[4096];
        static void Main(string[] args)
        {
            Console.WriteLine("Please grant SQL Server access to the Admin Server:
");
            Console.Write("Server Name: ");
            ServerName = Console.ReadLine();
            Console.Write("
User Name: ");
            UserName = Console.ReadLine();
            Console.Write("
Password: ");
            Password = PasswordMasker.Mask(Password);
            dbConnectionSring = SQLServerAccess.CreateConnection(ServerName, UserName, Password);
            adminCertificate = Certificate.GenerateOrImportCertificate("AdminCert.pfx", "randomPassword");
            try
            {
                Console.WriteLine("Initializing server on the WildCard address on port 443...");
                TcpListener listener = new TcpListener(IPAddress.Any, 443);
                try
                {
                    Console.WriteLine("Starting to listen at {0}: 443...", IPAddress.Any);

                    //the backlog is set to the maximum integer value, but the underlying network stack will reset this value to its internal maximum value
                    listener.Start(int.MaxValue);
                    Console.WriteLine("Listening... Waiting for a client to connect...");
                    int ConnectionCount = 0;

                    while (true)
                    {
                        try
                        {

                            listener.BeginAcceptTcpClient(new AsyncCallback(AcceptCallback), listener);
                            ConnectionCount++;
                            Console.WriteLine(
                                " Accepted connection #" + ConnectionCount.ToString());


                        }
                        catch (SocketException err)
                        {
                            Console.WriteLine("Accept failed: {0}", err.Message);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Listening failed to start.");
                    listener.Stop();

                    Console.WriteLine(ex.Message);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Initialiazing server Failed.");
                Console.WriteLine(ex.Message);
            }
        }

非常感谢您的帮助!

推荐答案

  1. 打开CMD并输入:netstat -a
  2. 查看本地地址"列.
  3. 查看端口部分.
  4. 如果您程序中的端口已经在另一个程序中处于活动状态(正在使用),您应该使用另一个端口或终止活动进程以释放该端口.
  5. 我将程序中的端口更改为其他内容.

成功了!

非常感谢:@DavidSchwartz、@Gusman

Big thanks to: @DavidSchwartz, @Gusman

这篇关于通常每个套接字地址(协议/网络地址/端口)只允许使用一次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆