public OverlayHost NewHost(OverlayHostName hostName, OverlayHost.ProcessorAssigner messageProcessor, MemoryStream extraHandshakeInfo, TimeSpan inactivityPeriod) { MyAssert.Assert(!hosts.ContainsKey(hostName)); OverlayHost host = new OverlayHost(hostName, MyAddress, processQueue, messageProcessor, extraHandshakeInfo, tt, inactivityPeriod); hosts.Add(hostName, host); Log.EntryConsole(log, "New host: " + hostName); return(host); }
private void StartListening() { IPAddress ip = myIP; Socket sckListen = new Socket( ip.AddressFamily, SocketType.Stream, ProtocolType.Tcp); try { int i; for (i = 0; i < nPortTries; ++i) { try { int nPort = nStartPort + i; MyAddress = new IPEndPoint(ip, nPort); sckListen.Bind(MyAddress); Log.EntryConsole(log, "Listening at {0}:{1}", ip, nPort); break; } catch (SocketException) { } } if (i == nPortTries) { throw new Exception("Unsucessful binding to ports"); } sckListen.Listen(10); sl = new SocketListener(processQueue, (info, sck) => this.NewIncomingConnection(info, sck), sckListen); } catch (Exception) { sckListen.Close(); throw; } }