Пример #1
0
        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);
            _connection = new RtmpClientConnection(this, socket);
            _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
        }
Пример #2
0
 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);
     }
 }