/// <summary> /// Create a new connection object. /// This connection will create a socket and bind itself to a free port. /// /// Throws URISyntaxException there was a problem generating the connection /// dependent part of the URI /// Throws IOException if there was a problem with the creation of the /// socket /// </summary> /// <param name="address">hostname/IP used to bound the new MSRP socket</param> public Connection(IPAddress address) { _preParser = new PreParser(this); _random = new Random(); TransactionManager = new TransactionManager(this); // activate the connection: if (NetworkUtils.isLinkLocalIPv4Address(address)) { _logger.Info(string.Format("Connection: given address is a local one: {0}", address)); } _socket = new Socket(address.AddressFamily, SocketType.Stream, ProtocolType.Tcp); //socketChannel; _socket.Blocking = true; //TODO : Property maken van socket, en dan als deze wordt gezet direct Blocking = true zetten IPEndPoint endpoint = new IPEndPoint(address, 0); _socket.Bind(endpoint); // fill the localURI variable that contains the uri parts that are // associated with this connection (scheme[protocol], host and port) endpoint = (IPEndPoint)_socket.LocalEndPoint; Uri newLocalURI = new Uri(string.Format("msrp://{0}:{1}", endpoint.Address, endpoint.Port)); //new Uri("msrp", null, address.getHostAddress(), socket.getLocalPort(), null, null, null); LocalURI = newLocalURI; }
/// <summary> /// Constructor /// </summary> /// <param name="newSocketChannel"></param> public Connection(Socket newSocketChannel) { _preParser = new PreParser(this); _random = new Random(); _socket = newSocketChannel; _socket.Blocking = true; //TODO : Property maken van socket, en dan als deze wordt gezet direct Blocking = true zetten IPEndPoint endpoint = (IPEndPoint)_socket.RemoteEndPoint; Uri newLocalURI = new Uri(string.Format("msrp://{0}:{1}", endpoint.Address, endpoint.Port)); //new Uri("msrp", null, socket.getHostAddress(), socket.getLocalPort(), null, null, null); LocalURI = newLocalURI; TransactionManager = new TransactionManager(this); }
/// <summary> /// /// </summary> public Connection() { _preParser = new PreParser(this); }