Exemple #1
0
        /// <summary>
        /// 启动ws
        /// </summary>
        /// <param name="bindIp"></param>
        /// <param name="bindWebsocketPort"></param>
        void WebSocketListener(string bindIp, int bindWebsocketPort)
        {
            var websocketServer = new WebSocketServer("ws://" + bindIp.ToString() + ":" + bindWebsocketPort.ToString());

            if (this.Certificate != null)
            {
                websocketServer.Certificate         = Certificate;
                websocketServer.EnabledSslProtocols = SslProtocols.Default;
            }
            websocketServer.ListenerSocket.NoDelay = true;

            websocketServer.Start(wsSocket =>
            {
                wsSocket.OnOpen = () =>
                {
                    var path = wsSocket.ConnectionInfo.Path.Split('/');

                    if (path.Length != 3)
                    {
                        wsSocket.Close();
                    }

                    ushort clientID = GetNewClientId();

                    RegisterPlay(path[1], path[2], clientID);

                    IStreamConnect wsConnect = new WebsocketConnect(this, wsSocket, clientID, this.Context, this.AmfEncoding);

                    ClientSessions.Add(clientID, new ClientSession()
                    {
                        Connect    = wsConnect,
                        LastPing   = DateTime.UtcNow,
                        ReaderTask = null,
                        WriterTask = null
                    });

                    try
                    {
                        SendMetadataToPlayer(path[1], path[2], wsConnect, flvHeader: true);
                        ConnectToClient(path[1], path[2], clientID, ChannelType.Audio);
                        ConnectToClient(path[1], path[2], clientID, ChannelType.Video);
                    }
                    catch (Exception ex)
                    {
                        FleckLog.Error("ws请求了一个不存在的直播,请检查直播地址是否有误或检查直播状态,error:", ex);
                        DisconnectSession(clientID);
                    }
                };
                wsSocket.OnPing = b => wsSocket.SendPong(b);
            });
        }
Exemple #2
0
        public override ServerInfo ProcessData(CClientInfo Request)
        {
            ServerInfo Reply = new ServerInfo();
            uint       ID    = Request.ClientID;

            if (ClientSessions.ContainsKey(ID) == false)
            {
                if (ClientSessions.Count < RGOServiceBase.maxNrClients)
                {
                    var clientConn = new RGOClientConnection(ID)
                    {
                        IsLocal        = Connection.IsOnLoopback,
                        BatchSize      = RGOServiceBase.LocalBatchsize,
                        ConnectionName = Connection.Address
                    };
                    if (!Connection.IsOnLoopback)
                    {
                        clientConn.BatchSize = RGOServiceBase.RemoteBatchsize;
                    }

                    ClientSessions.Add(ID, clientConn);


                    Reply.ConnectionAccepted = true;
                }
                else
                {
                    Reply.ConnectionAccepted = false;
                }
            }
            else
            {
                ClientSessions[ID].ClientCommCounter = Request.Counter;
                log.Debug($"Client: {Request.ClientID}, counter:{Request.Counter}");

                Reply.SetTime();
                Reply.SessionCounter     = Request.Counter;
                Reply.CycleTime          = RGOServiceStarter.MeasuredCycleTime;
                Reply.ConnectionAccepted = true;
            }

            return(Reply);
        }
        public async Task <ActionResult <string> > Push(LogViewModel data)
        {
            try
            {
                var item = populteListItem(data);
                ClientSessions.Add(item);

                ViewUpdater.Update();

                using (var client = new HttpClient())
                {
                    var response = await client.PostAsJsonAsync("http://clients.ranpod.com/api/data/push", data);

                    return(StatusCode((int)response.StatusCode, $"Server response :{await response.Content.ReadAsStringAsync()}"));
                }
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ex.ToString()));

                throw;
            }
        }