Guest User

Untitled

a guest
Nov 21st, 2018
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.64 KB | None | 0 0
  1. class Program
  2. {
  3. private static string ServerName = "";
  4. private static string UserName = "";
  5. private static string Password = "";
  6. private static string dbConnectionSring = "";
  7. private static X509Certificate adminCertificate;
  8. private static byte[] readBuffer = new byte[4096];
  9. static void Main(string[] args)
  10. {
  11. Console.WriteLine("Please grant SQL Server access to the Admin Server:n");
  12. Console.Write("Server Name: ");
  13. ServerName = Console.ReadLine();
  14. Console.Write("nUser Name: ");
  15. UserName = Console.ReadLine();
  16. Console.Write("nPassword: ");
  17. Password = PasswordMasker.Mask(Password);
  18. dbConnectionSring = SQLServerAccess.CreateConnection(ServerName, UserName, Password);
  19. adminCertificate = Certificate.GenerateOrImportCertificate("AdminCert.pfx", "randomPassword");
  20. try
  21. {
  22. Console.WriteLine("Initializing server on the WildCard address on port 443...");
  23. TcpListener listener = new TcpListener(IPAddress.Any, 443);
  24. try
  25. {
  26. Console.WriteLine("Starting to listen at {0}: 443...", IPAddress.Any);
  27.  
  28. //the backlog is set to the maximum integer value, but the underlying network stack will reset this value to its internal maximum value
  29. listener.Start(int.MaxValue);
  30. Console.WriteLine("Listening... Waiting for a client to connect...");
  31. int ConnectionCount = 0;
  32.  
  33. while (true)
  34. {
  35. try
  36. {
  37.  
  38. listener.BeginAcceptTcpClient(new AsyncCallback(AcceptCallback), listener);
  39. ConnectionCount++;
  40. Console.WriteLine(
  41. " Accepted connection #" + ConnectionCount.ToString());
  42.  
  43.  
  44. }
  45. catch (SocketException err)
  46. {
  47. Console.WriteLine("Accept failed: {0}", err.Message);
  48. }
  49. }
  50. }
  51. catch (Exception ex)
  52. {
  53. Console.WriteLine("Listening failed to start.");
  54. listener.Stop();
  55.  
  56. Console.WriteLine(ex.Message);
  57. }
  58. }
  59. catch (Exception ex)
  60. {
  61. Console.WriteLine("Initialiazing server Failed.");
  62. Console.WriteLine(ex.Message);
  63. }
  64. }
Add Comment
Please, Sign In to add comment