Exemple #1
0
        private void ReturnMessage(RtmptConnection connection, ByteBuffer data, RtmptRequest request)
        {
            ByteBuffer   stream = ByteBuffer.Allocate(((int)data.Length) + 30);
            StreamWriter writer = new StreamWriter(stream);
            int          num    = data.Limit + 1;

            if (request.HttpVersion == 1)
            {
                writer.Write("HTTP/1.1 200 OK\r\n");
                writer.Write("Cache-Control: no-cache\r\n");
            }
            else
            {
                writer.Write("HTTP/1.0 200 OK\r\n");
                writer.Write("Pragma: no-cache\r\n");
            }
            writer.Write(string.Format("Content-Length: {0}\r\n", num));
            writer.Write("Connection: Keep-Alive\r\n");
            writer.Write(string.Format("Content-Type: {0}\r\n", "application/x-fcs"));
            writer.Write("\r\n");
            writer.Write((char)connection.PollingDelay);
            writer.Flush();
            BinaryWriter writer2 = new BinaryWriter(stream);

            byte[] buffer = data.ToArray();
            writer2.Write(buffer);
            writer2.Flush();
            request.Connection.Send(stream);
        }
Exemple #2
0
        private void HandleOpen(HttpRequest request, HttpResponse response)
        {
            Unreferenced.Parameter(request);
            //Pass a null IPEndPoint, for this connection will create it on demand
            RtmptConnection connection = new RtmptConnection(this, null, null, null);

            FluorineRtmpContext.Initialize(connection);

            /*
             * HttpSession session = _endpoint.GetMessageBroker().SessionManager.GetHttpSession(HttpContext.Current);
             * FluorineContext.Current.SetSession(session);
             * RtmptConnection connection = new RtmptConnection(this, null, session, null, null);
             * Client client = this.Endpoint.GetMessageBroker().ClientRegistry.GetClient(connection.ConnectionId) as Client;
             * FluorineContext.Current.SetClient(client);
             * FluorineContext.Current.SetConnection(connection);
             * connection.Initialize(client);
             * //Current object are set notify listeners.
             * if (session != null && session.IsNew)
             *  session.NotifyCreated();
             * if (client != null)
             * {
             *  client.RegisterSession(session);
             *  client.NotifyCreated();
             * }
             */
            _connections[connection.ConnectionId] = connection;
            // Return connection id to client
            ReturnMessage(connection.ConnectionId + "\n", response);
        }
Exemple #3
0
        private void HandleOpen(HttpRequest request, HttpResponse response)
        {
            RtmptConnection connection = new RtmptConnection(this, null, null);

            this._connections[connection.ConnectionId] = connection;
            this.ReturnMessage(connection.ConnectionId + "\n", response);
        }
Exemple #4
0
        private void ReturnMessage(RtmptConnection connection, ByteBuffer data, RtmptRequest request)
        {
            ByteBuffer   buffer        = ByteBuffer.Allocate((int)data.Length + 30);
            StreamWriter sw            = new StreamWriter(buffer);
            int          contentLength = data.Limit + 1;

            if (request.HttpVersion == 1)
            {
                sw.Write("HTTP/1.1 200 OK\r\n");
                sw.Write("Cache-Control: no-cache\r\n");
            }
            else
            {
                sw.Write("HTTP/1.0 200 OK\r\n");
                sw.Write("Pragma: no-cache\r\n");
            }
            sw.Write(string.Format("Content-Length: {0}\r\n", contentLength));
            sw.Write("Connection: Keep-Alive\r\n");
            sw.Write(string.Format("Content-Type: {0}\r\n", ContentType.RTMPT));
            sw.Write("\r\n");
            sw.Write((char)connection.PollingDelay);
            sw.Flush();
            BinaryWriter bw = new BinaryWriter(buffer);

            byte[] buf = data.ToArray();
            bw.Write(buf);
            bw.Flush();
            request.Connection.Write(buffer);
        }
Exemple #5
0
        private void HandleOpen(RtmptRequest request)
        {
            RtmptConnection connection = new RtmptConnection(request.Connection.RemoteEndPoint, this, null, null);

            this._connections[connection.ConnectionId] = connection;
            this.ReturnMessage(connection.ConnectionId + "\n", request);
        }
Exemple #6
0
        private void HandleIdent(RtmptRequest request)
        {
            RtmptConnection connection = new RtmptConnection(this, request.Connection.RemoteEndPoint, null, null);

            FluorineRtmpContext.Initialize(connection);
            _connections[connection.ConnectionId] = connection;
            // Return connection id to client
            ReturnMessage(Ident, request);
        }
Exemple #7
0
 private void ReturnMessage(RtmptConnection connection, ByteBuffer data, HttpResponse response)
 {
     response.StatusCode = 200;
     response.ClearHeaders();
     response.AppendHeader("Connection", "Keep-Alive");
     response.AppendHeader("Content-Length", (data.Limit + 1).ToString());
     response.Cache.SetCacheability(HttpCacheability.NoCache);
     response.ContentType = "application/x-fcs";
     response.Write((char)connection.PollingDelay);
     byte[] buffer = data.ToArray();
     response.OutputStream.Write(buffer, 0, buffer.Length);
     response.Flush();
 }
Exemple #8
0
        private void HandleSend(HttpRequest request, HttpResponse response)
        {
            RtmptConnection connection = this.GetConnection(request);

            if (connection == null)
            {
                this.HandleBadRequest(__Res.GetString("Rtmpt_UnknownClient", new object[] { this.GetHttpRequestPath(request) }), response);
            }
            else
            {
                if (connection.Client != null)
                {
                    connection.Client.Renew();
                }
                int    contentLength = request.ContentLength;
                byte[] buffer        = new byte[request.InputStream.Length];
                request.InputStream.Read(buffer, 0, (int)request.InputStream.Length);
                ByteBuffer data = ByteBuffer.Wrap(buffer);
                IList      list = connection.Decode(data);
                if ((list == null) || (list.Count == 0))
                {
                    this.ReturnMessage(connection.PollingDelay, response);
                }
                else
                {
                    foreach (object obj2 in list)
                    {
                        try
                        {
                            if (obj2 is ByteBuffer)
                            {
                                ByteBuffer packet = obj2 as ByteBuffer;
                                connection.RawWrite(packet);
                            }
                            else
                            {
                                (FluorineContext.Current as FluorineWebContext).SetConnection(connection);
                                this._rtmpHandler.MessageReceived(connection, obj2);
                            }
                        }
                        catch (Exception exception)
                        {
                            log.Error(__Res.GetString("Rtmp_CouldNotProcessMessage"), exception);
                        }
                    }
                    this.ReturnPendingMessages(connection, response);
                }
            }
        }
Exemple #9
0
        private void HandleClose(RtmptRequest request)
        {
            RtmptConnection connection = GetConnection(request);

            if (connection == null)
            {
                HandleBadRequest(__Res.GetString(__Res.Rtmpt_UnknownClient, request.Url), request);
                return;
            }
            FluorineRtmpContext.Initialize(connection);
            RemoveConnection(connection.ConnectionId);
            _rtmpHandler.ConnectionClosed(connection);
            ReturnMessage(0, request);
            connection.RealClose();
        }
Exemple #10
0
        private void HandleSend(RtmptRequest request)
        {
            RtmptConnection connection = this.GetConnection(request);

            if (connection == null)
            {
                this.HandleBadRequest(__Res.GetString("Rtmpt_UnknownClient", new object[] { request.Url }), request);
            }
            else
            {
                if (connection.Client != null)
                {
                    connection.Client.Renew();
                }
                int        contentLength = request.ContentLength;
                ByteBuffer data          = request.Data;
                IList      list          = connection.Decode(data);
                if ((list == null) || (list.Count == 0))
                {
                    this.ReturnMessage(connection.PollingDelay, request);
                }
                else
                {
                    foreach (object obj2 in list)
                    {
                        try
                        {
                            if (obj2 is ByteBuffer)
                            {
                                ByteBuffer packet = obj2 as ByteBuffer;
                                connection.RawWrite(packet);
                            }
                            else
                            {
                                FluorineRtmpContext.Initialize(connection);
                                this._rtmpHandler.MessageReceived(connection, obj2);
                            }
                        }
                        catch (Exception exception)
                        {
                            log.Error(__Res.GetString("Rtmp_CouldNotProcessMessage"), exception);
                        }
                    }
                    this.ReturnPendingMessages(connection, request);
                }
            }
        }
Exemple #11
0
        private void HandleSend(HttpRequest request, HttpResponse response)
        {
            RtmptConnection connection = GetConnection(request);

            if (connection == null)
            {
                HandleBadRequest(__Res.GetString(__Res.Rtmpt_UnknownClient, GetHttpRequestPath(request)), response);
                return;
            }
            FluorineRtmpContext.Initialize(connection);
            //int length = request.ContentLength;
            byte[] data = new byte[request.InputStream.Length];
            request.InputStream.Read(data, 0, (int)request.InputStream.Length);
            ByteBuffer buffer   = ByteBuffer.Wrap(data);
            IList      messages = connection.Decode(buffer);

            if (messages == null || messages.Count == 0)
            {
                ReturnMessage(connection.PollingDelay, response);
                return;
            }
            // Execute the received RTMP messages
            foreach (object message in messages)
            {
                try
                {
                    if (message is ByteBuffer)
                    {
                        connection.Write(message as ByteBuffer);
                    }
                    else if (message is byte[])
                    {
                        connection.Write(message as byte[]);
                    }
                    else
                    {
                        _rtmpHandler.MessageReceived(connection, message);
                    }
                }
                catch (Exception ex)
                {
                    Log.Error(__Res.GetString(__Res.Rtmp_CouldNotProcessMessage), ex);
                }
            }
            // Send results to client
            ReturnPendingMessages(connection, response);
        }
Exemple #12
0
        private void HandleClose(HttpRequest request, HttpResponse response)
        {
            RtmptConnection connection = this.GetConnection(request);

            if (connection == null)
            {
                this.HandleBadRequest(__Res.GetString("Rtmpt_UnknownClient", new object[] { this.GetHttpRequestPath(request) }), response);
            }
            else
            {
                if (connection.Client != null)
                {
                    connection.Client.Renew();
                }
                connection.DeferredClose();
                this.ReturnMessage((byte)0, response);
            }
        }
Exemple #13
0
        private void HandleIdle(RtmptRequest request)
        {
            RtmptConnection connection = GetConnection(request);

            if (connection == null)
            {
                HandleBadRequest(__Res.GetString(__Res.Rtmpt_UnknownClient, request.Url), request);
                return;
            }
            if (connection.IsClosing)
            {
                // Tell client to close the connection
                ReturnMessage(0, request);
                connection.RealClose();
                return;
            }
            FluorineRtmpContext.Initialize(connection);
            ReturnPendingMessages(connection, request);
        }
Exemple #14
0
        private void ReturnPendingMessages(RtmptConnection connection, RtmptRequest request)
        {
            ByteBuffer data = connection.GetPendingMessages(RtmptConnection.RESPONSE_TARGET_SIZE);

            if (data == null)
            {
                // no more messages to send...
                if (connection.IsClosing)
                {
                    // Tell client to close connection
                    ReturnMessage(0, request);
                }
                else
                {
                    ReturnMessage(connection.PollingDelay, request);
                }
                return;
            }
            ReturnMessage(connection, data, request);
        }
Exemple #15
0
        private void ReturnPendingMessages(RtmptConnection connection, HttpResponse response)
        {
            ByteBuffer pendingMessages = connection.GetPendingMessages(RESPONSE_TARGET_SIZE);

            if (pendingMessages == null)
            {
                if (connection.IsClosing)
                {
                    this.ReturnMessage((byte)0, response);
                }
                else
                {
                    this.ReturnMessage(connection.PollingDelay, response);
                }
            }
            else
            {
                this.ReturnMessage(connection, pendingMessages, response);
            }
        }
Exemple #16
0
        private void HandleIdle(RtmptRequest request)
        {
            RtmptConnection connection = this.GetConnection(request);

            if (connection == null)
            {
                this.HandleBadRequest(__Res.GetString("Rtmpt_UnknownClient", new object[] { request.Url }), request);
            }
            else if (connection.IsClosing)
            {
                this.ReturnMessage((byte)0, request);
                connection.DeferredClose();
            }
            else
            {
                if (connection.Client != null)
                {
                    connection.Client.Renew();
                }
                this.ReturnPendingMessages(connection, request);
            }
        }
 private void ReturnPendingMessages(RtmptConnection connection, RtmptRequest request)
 {
     ByteBuffer data = connection.GetPendingMessages(RtmptConnection.RESPONSE_TARGET_SIZE);
     if (data == null)
     {
         // no more messages to send...
         if (connection.IsClosing)
         {
             // Tell client to close connection
             ReturnMessage(0, request);
         }
         else
             ReturnMessage(connection.PollingDelay, request);
         return;
     }
     ReturnMessage(connection, data, request);
 }
 private void ReturnMessage(RtmptConnection connection, ByteBuffer data, RtmptRequest request)
 {
     ByteBuffer buffer = ByteBuffer.Allocate((int)data.Length + 30);
     StreamWriter sw = new StreamWriter(buffer);
     int contentLength = data.Limit + 1;
     if (request.HttpVersion == 1)
     {
         sw.Write("HTTP/1.1 200 OK\r\n");
         sw.Write("Cache-Control: no-cache\r\n");
     }
     else
     {
         sw.Write("HTTP/1.0 200 OK\r\n");
         sw.Write("Pragma: no-cache\r\n");
     }
     sw.Write(string.Format("Content-Length: {0}\r\n", contentLength));
     sw.Write("Connection: Keep-Alive\r\n");
     sw.Write(string.Format("Content-Type: {0}\r\n", ContentType.RTMPT));
     sw.Write("\r\n");
     sw.Write((char)connection.PollingDelay);
     sw.Flush();
     BinaryWriter bw = new BinaryWriter(buffer);
     byte[] buf = data.ToArray();
     bw.Write(buf);
     bw.Flush();
     request.Connection.Write(buffer);
 }
 private void ReturnMessage(RtmptConnection connection, ByteBuffer data, HttpResponse response)
 {
     response.StatusCode = 200;
     response.ClearHeaders();
     response.AppendHeader("Connection", "Keep-Alive");
     int contentLength = data.Limit + 1;
     response.AppendHeader("Content-Length", contentLength.ToString());
     response.Cache.SetCacheability(HttpCacheability.NoCache);
     response.ContentType = ContentType.RTMPT;
     response.Write((char)connection.PollingDelay);
     byte[] buffer = data.ToArray();
     response.OutputStream.Write(buffer, 0, buffer.Length);
     response.Flush();            
 }
 private void HandleIdent(RtmptRequest request)
 {
     RtmptConnection connection = new RtmptConnection(this, request.Connection.RemoteEndPoint, null, null);
     FluorineRtmpContext.Initialize(connection);
     _connections[connection.ConnectionId] = connection;
     // Return connection id to client
     ReturnMessage(Ident, request);
 }
 private void HandleOpen(HttpRequest request, HttpResponse response)
 {
     Unreferenced.Parameter(request);
     //Pass a null IPEndPoint, for this connection will create it on demand
     RtmptConnection connection = new RtmptConnection(this, null, null, null);
     FluorineRtmpContext.Initialize(connection);
     /*
     HttpSession session = _endpoint.GetMessageBroker().SessionManager.GetHttpSession(HttpContext.Current);
     FluorineContext.Current.SetSession(session);
     RtmptConnection connection = new RtmptConnection(this, null, session, null, null);
     Client client = this.Endpoint.GetMessageBroker().ClientRegistry.GetClient(connection.ConnectionId) as Client;
     FluorineContext.Current.SetClient(client);
     FluorineContext.Current.SetConnection(connection);
     connection.Initialize(client);
     //Current object are set notify listeners.
     if (session != null && session.IsNew)
         session.NotifyCreated();
     if (client != null)
     {
         client.RegisterSession(session);
         client.NotifyCreated();
     }
     */
     _connections[connection.ConnectionId] = connection;
     // Return connection id to client
     ReturnMessage(connection.ConnectionId + "\n", response);
 }
Exemple #22
0
 internal void OnConnectionClose(RtmptConnection connection)
 {
     this._connections.Remove(connection.ConnectionId);
 }