Я искал серьезное решение для google, и я получаю только «решения Regisrty», которые, я думаю, даже не относятся к моей проблеме.Обычно разрешено только одно использование каждого адреса сокета (протокол/сетевой адрес/порт)?
По какой-то причине я получаю эту ошибку, в то время как я только запускаю TcpListner один раз, а когда +, если не удается, я останавливаю сервер. Я действительно не понимаю. Вот мой код:
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:\n");
Console.Write("Server Name: ");
ServerName = Console.ReadLine();
Console.Write("\nUser Name: ");
UserName = Console.ReadLine();
Console.Write("\nPassword: ");
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);
}
}
Я очень ценю вашу помощь!
Проблема другая программа уже прослушивает этот порт ... – Gusman
Вы можете попробовать либо другой порт или привязки к конкретному локальному IP адрес, а не все из них. –
@DavidSchwartz Как я могу узнать, какие порты можно использовать бесплатно? – WeinForce