// Protected constructor is sufficient to suppress unauthorized calls to the // constructor protected Connection Connection() { try { _random = new Random(); bool localAddress = false; InetAddress newAddress = InetAddress.LocalHostName; // sanity check, check that the given address is a local one where a // socket // could be bound InetAddress[] local = InetAddress.GetAllByName(InetAddress.LocalHostName.HostName); foreach (InetAddress inetAddress in local) { if (inetAddress.Equals(newAddress)) { localAddress = true; } } if (!localAddress) { throw new UriFormatException("the given adress is not a local one"); } // bind the socket to a local temp. port. _serverSocketChannel = new Socket(new SocketInformation()); //SelectorProvider.provider().openServerSocketChannel(); _serverSocketChannel.Bind(new IPEndPoint(newAddress._addr, 0)); // fill the localURI variable that contains the uri parts that are // associated with this connection (scheme[protocol], host and port) //Uri newLocalURI = new Uri("msrp", null, newAddress.getHostAddress(), socket.getLocalPort(), null, null, null); LocalURI = new Uri(string.Format("msrp://{0}:{1}", newAddress.HostAddress, _serverSocketChannel.GetLocalPort())); } catch (Exception e) { _logger.Error("Error! Connection did not get an associated socket"); } return(this); }