public void Connect(string command, params object[] arguments) { Uri uri = new Uri(command); _connectArguments = arguments; int port = uri.Port <= 0 ? 1935 : uri.Port; //_connectionParameters["tcUrl"] = "rtmp://" + uri.Host + (uri.Port > 0 ? uri.Port.ToString() + ':' : string.Empty) + uri.PathAndQuery; _connectionParameters["tcUrl"] = command; string app = uri.LocalPath.TrimStart(new char[] { '/' }); _connectionParameters["app"] = app; Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); #if !SILVERLIGHT socket.Connect(uri.Host, port); var usingSsl = uri.Scheme == "rtmps"; _connection = new RtmpClientConnection(this, socket, usingSsl, uri.Host); _connection.Context.ObjectEncoding = _netConnection.ObjectEncoding; _connection.BeginHandshake(); #else DnsEndPoint endPoint = new DnsEndPoint(uri.Host, port); SocketAsyncEventArgs args = new SocketAsyncEventArgs(); args.UserToken = socket; args.RemoteEndPoint = endPoint; args.Completed += new EventHandler <SocketAsyncEventArgs>(OnSocketConnectCompleted); socket.ConnectAsync(args); #endif }
public void Connect(string command, params object[] arguments) { Uri uri = new Uri(command); _connectArguments = arguments; int port = uri.Port <= 0 ? 1935 : uri.Port; //_connectionParameters["tcUrl"] = "rtmp://" + uri.Host + (uri.Port > 0 ? uri.Port.ToString() + ':' : string.Empty) + uri.PathAndQuery; _connectionParameters["tcUrl"] = command; string app = uri.LocalPath.TrimStart(new char[] { '/' }); _connectionParameters["app"] = app; Socket socket = null; // Support for proxies in non-Silverlight apps. #if !SILVERLIGHT if (Proxy != null) { ProxyClientFactory factory = new ProxyClientFactory(); string[] proxyParts = _proxy.Server.Split(':'); IProxyClient proxyClient = factory.CreateProxyClient(_proxy.TypeToInternalType(), proxyParts[0], int.Parse(proxyParts[1])); Uri endpoint = new Uri(command); TcpClient tcpClient = proxyClient.CreateConnection(endpoint.Host, endpoint.Port); socket = tcpClient.Client; } else { socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); socket.Connect(uri.Host, port); } #else socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); #endif #if !SILVERLIGHT _connection = new RtmpClientConnection(this, socket, _secure, uri.Host); _connection.Context.ObjectEncoding = _netConnection.ObjectEncoding; _connection.BeginHandshake(); #else DnsEndPoint endPoint = new DnsEndPoint(uri.Host, port); SocketAsyncEventArgs args = new SocketAsyncEventArgs(); args.UserToken = socket; args.RemoteEndPoint = endPoint; args.Completed += new EventHandler <SocketAsyncEventArgs>(OnSocketConnectCompleted); socket.ConnectAsync(args); #endif }
private void OnSocketConnectCompleted(object sender, SocketAsyncEventArgs e) { try { Socket socket = (Socket)e.UserToken; if (e.SocketError != SocketError.Success) { _netConnection.RaiseNetStatus(StatusASO.NC_CONNECT_FAILED, new SocketException((int)e.SocketError)); socket.Close(); } else { _connection = new RtmpClientConnection(this, socket); _connection.Context.ObjectEncoding = _netConnection.ObjectEncoding; _connection.BeginHandshake(); } } catch (Exception ex) { _netConnection.RaiseNetStatus(ex); } }