Changeset 14263 for branches/thasling/DistributedGA
- Timestamp:
- 08/22/16 12:06:01 (8 years ago)
- Location:
- branches/thasling/DistributedGA
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/thasling/DistributedGA/DistributedGA.Core/Implementation/WcfMessageService.cs
r14252 r14263 1 1 using System; 2 2 using System.Net; 3 using System.Net.NetworkInformation; 3 4 using System.Net.Sockets; 4 5 using System.ServiceModel; … … 24 25 var serviceUrl = "DistributedGA.svc"; 25 26 new Thread(() => { 26 var baseUri = new Uri(string.Concat("net.tcp://", ip, ":", port, "/DistributedGA")); 27 var serviceUri = new Uri(baseUri, serviceUrl); 28 NetTcpBinding binding = new NetTcpBinding(); 29 binding.MaxReceivedMessageSize = 20000000; 30 binding.MaxBufferSize = 20000000; 31 binding.MaxBufferPoolSize = 20000000; 32 binding.ReaderQuotas.MaxArrayLength = 20000000; 33 binding.ReaderQuotas.MaxDepth = 32; 34 binding.ReaderQuotas.MaxStringContentLength = 20000000; 27 try { 28 var baseUri = new Uri(string.Concat("net.tcp://", ip, ":", port, "/DistributedGA")); 29 var serviceUri = new Uri(baseUri, serviceUrl); 30 NetTcpBinding binding = new NetTcpBinding(); 31 binding.MaxReceivedMessageSize = 20000000; 32 binding.MaxBufferSize = 20000000; 33 binding.MaxBufferPoolSize = 20000000; 34 binding.ReaderQuotas.MaxArrayLength = 20000000; 35 binding.ReaderQuotas.MaxDepth = 32; 36 binding.ReaderQuotas.MaxStringContentLength = 20000000; 35 37 36 using (var host = new ServiceHost(messageContract, serviceUri)) {37 host.AddServiceEndpoint(typeof(IMessageContract), binding, serviceUri);38 using (var host = new ServiceHost(messageContract, serviceUri)) { 39 host.AddServiceEndpoint(typeof(IMessageContract), binding, serviceUri); 38 40 39 host.Open();41 host.Open(); 40 42 41 _ResetEvent.WaitOne(); 43 _ResetEvent.WaitOne(); 44 } 45 } 46 catch (Exception ex) { 47 int k = 0; 48 int j = 0; 42 49 } 43 50 }).Start(); 44 51 return port; 52 45 53 } 46 54 … … 50 58 } 51 59 60 private bool IsPortAvaiable(int port) { 61 //int port = 456; //<--- This is your value 62 bool isAvailable = true; 63 64 // Evaluate current system tcp connections. This is the same information provided 65 // by the netstat command line application, just in .Net strongly-typed object 66 // form. We will look through the list, and if our port we would like to use 67 // in our TcpClient is occupied, we will set isAvailable to false. 68 IPGlobalProperties ipGlobalProperties = IPGlobalProperties.GetIPGlobalProperties(); 69 TcpConnectionInformation[] tcpConnInfoArray = ipGlobalProperties.GetActiveTcpConnections(); 70 foreach (TcpConnectionInformation tcpi in tcpConnInfoArray) { 71 if (tcpi.LocalEndPoint.Port == port) { 72 isAvailable = false; 73 break; 74 } 75 } 76 foreach (var item in ipGlobalProperties.GetActiveTcpListeners()) { 77 if (item.Port == port) { 78 isAvailable = false; 79 break; 80 } 81 } 82 return isAvailable; 83 } 84 52 85 private int FreeTcpPort() { 53 TcpListener l = new TcpListener(IPAddress.Loopback, 0);54 l.Start();55 int port = ((IPEndPoint)l.LocalEndpoint).Port;56 l.Stop();57 return port;86 for (int i = 11000; i <= 11100; i++) { 87 if (IsPortAvaiable(i)) 88 return i; 89 } 90 return 0; 58 91 } 92 93 //private int FreeTcpPort() { 94 // TcpListener l = new TcpListener(IPAddress.Loopback, 0); 95 // l.Start(); 96 // int port = ((IPEndPoint)l.LocalEndpoint).Port; 97 // l.Stop(); 98 // return port; 99 //} 59 100 60 101 private void OnMessageRecieved(object sender, MessageRecieveEventArgs e) { -
branches/thasling/DistributedGA/DistributedGA.sln
r14261 r14263 50 50 HideSolutionNode = FALSE 51 51 EndGlobalSection 52 GlobalSection(Performance) = preSolution53 HasPerformanceSessions = true54 EndGlobalSection55 52 EndGlobal
Note: See TracChangeset
for help on using the changeset viewer.