public override void Stop() { try { if (log.IsInfoEnabled) { log.Info(__Res.GetString(__Res.RtmpEndpoint_Stopping)); } if (_rtmpServer != null) { _rtmpServer.Stop(); _rtmpServer.OnError -= new ErrorHandler(OnError); _rtmpServer.Dispose(); _rtmpServer = null; } if (log.IsInfoEnabled) { log.Info(__Res.GetString(__Res.RtmpEndpoint_Stopped)); } } catch (Exception ex) { if (log.IsFatalEnabled) { log.Fatal(__Res.GetString(__Res.RtmpEndpoint_Failed), ex); } } }
public override void Stop() { try { if (log.get_IsInfoEnabled()) { log.Info(__Res.GetString("RtmpEndpoint_Stopping")); } if (this._rtmpServer != null) { this._rtmpServer.Stop(); this._rtmpServer.OnError -= new ErrorHandler(this.OnError); this._rtmpServer.Dispose(); this._rtmpServer = null; } if (log.get_IsInfoEnabled()) { log.Info(__Res.GetString("RtmpEndpoint_Stopped")); } } catch (Exception exception) { if (log.get_IsFatalEnabled()) { log.Fatal(__Res.GetString("RtmpEndpoint_Failed"), exception); } } }
public WebsocketConnect(RtmpServer server, IWebSocketConnection connection, ushort clientID, SerializationContext context, ObjectEncoding encoding) { this.connection = connection; this.ClientID = clientID; this.StreamID = server.RequestStreamId(); IsPlaying = true; sendPing = connection.SendPing; connectTime = DateTime.UtcNow; connection.OnPong += d => callbackManager.SetResult(BitConverter.ToInt32(d, 0), null); connection.OnClose += () => { OnDisconnected(new ExceptionalEventArgs("Closed")); }; connection.OnError += (e) => { OnDisconnected(new ExceptionalEventArgs(e.Message, e)); }; var stream = new WebsocketStream(connection); writer = new FlvPacketWriter(new AmfWriter(stream, context), encoding); reader = new RtmpPacketReader(new AmfReader(stream, context)); //启动输出任务 writer.WriteLoopAsync(); }
static void Main(string[] args) { RtmpServer server = new RtmpServer(new RtmpSharp.IO.SerializationContext()); server.RegisterApp("app"); server.Start(); }
static void Main(string[] args) { Console.Title = "Draven"; printHeader(); if (!DatabaseManager.InitConnection()) { Console.WriteLine("[ERR] Press any Key to exit... (Check your Database Connection)"); Console.ReadKey(); return; } //Create the Authentication Server to handle login requests and client page _auth = new AuthServer(AuthServer.HandleWebServ, AuthLocations); //Generate the SerializationContext _context = new SerializationContext(); var structures = Assembly.GetExecutingAssembly().GetTypes().Where(x => String.Equals(x.Namespace, "Draven.Structures", StringComparison.Ordinal)); foreach (Type ObjectType in structures) { _context.Register(ObjectType); } //Create the RTMPS server with the context and certificate _server = new RtmpServer(new IPEndPoint(IPAddress.Parse(RTMPSHost), RTMPSPort), _context); _server.ClientCommandReceieved += ClientCommandReceieved; _server.ClientMessageReceived += ClientMessageReceived; //Set up the handler _handler = new MessageHandler(); _handler.Register("LoginService"); _handler.Register("MatchmakerService"); _handler.Register("ClientFacadeService"); _handler.Register("InventoryService"); _handler.Register("MasteryBookService"); _handler.Register("SummonerRuneService"); _handler.Register("PlayerPreferencesService"); _handler.Register("LcdsGameInvitationService"); _handler.Register("LeaguesServiceProxy"); _handler.Register("SummonerIconService"); _handler.Register("LcdsServiceProxy"); _handler.Register("SummonerService"); _handler.Register("LcdsRerollService"); _handler.Register("SummonerTeamService"); _handler.Register("PlayerStatsService"); //Set up the property redirector _redirector = new PropertyRedirector(); Console.WriteLine("[LOG] AuthServer listening on port 8080"); _auth.Start(); _server.Listen(); while (true) { } }
/// <summary> /// ffmpeg -re -i test.mp4 -f flv -vcodec h264 -acodec aac "rtmp://127.0.0.1/wenli/live" /// ffplay "rtmp://127.0.0.1/wenli/live" /// </summary> /// <param name="args"></param> static void Main(string[] args) { Console.Title = "Wenli.Live.LiveServer"; RtmpServer rtmpServer = new RtmpServer(); rtmpServer.StartAsync(); Console.Read(); }
static async Task test_server() { var options = new RtmpServer.Options { // required parameters: Context = new SerializationContext(), }; using (var server = await RtmpServer.ConnectAsync(options, x => { })) server.Wait(); }
public PoroServer(PoroServerSettings settings) { _settings = settings; //Create the Authentication Server to handle login requests _auth = new AuthServer(HandleAuth, _settings.AuthLocations); //Load the certificate for the RTMPS server var certificateStore = new X509Store(StoreName.Root, StoreLocation.LocalMachine); certificateStore.Open(OpenFlags.MaxAllowed); //Store the certificate if it's not in the local store var _rtmpsCert = new X509Certificate2(_settings.CertFilename, ""); if (!StoreContainsCertificate(certificateStore.Certificates, _rtmpsCert)) { certificateStore.Add(_rtmpsCert); } certificateStore.Close(); //Generate the SerializationContext var context = new SerializationContext(); var structures = Assembly.GetExecutingAssembly().GetTypes().Where(x => String.Equals(x.Namespace, "PoroLib.Structures", StringComparison.Ordinal)); foreach (Type ObjectType in structures) { context.Register(ObjectType); } //Create the RTMPS server with the context and certificate _server = new RtmpServer(new IPEndPoint(IPAddress.Parse(_settings.RTMPSHost), _settings.RTMPSPort), context, _rtmpsCert); _server.ClientCommandReceieved += ClientCommandReceieved; _server.ClientMessageReceived += ClientMessageReceived; //Set up the handler _handler = new MessageHandler(); _handler.Register("LoginService"); _handler.Register("MatchmakerService"); _handler.Register("ClientFacadeService"); _handler.Register("InventoryService"); //Set up the forwarder _forwarder = new MessageForwarder(context); //Set up the property redirector _redirector = new PropertyRedirector(_settings); }
public void Start() { server = new RtmpServerBuilder() .UseStartup <RtmpStartup>() .UseHarmonic(config => { options = config; }) .UseWebSocket(c => { c.BindEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), 8080); }) .Build(); tokenSource = new CancellationTokenSource(); serverTask = server.StartAsync(tokenSource.Token); }
static async void BotServerAsync() { Console.WriteLine("Bot server starting."); var options = new RtmpServer.Options { Url = "rtmp://any:4000", }; using (botServer = await RtmpServer.ConnectAsync(options, client => { client.DispatchMessage = s => { Console.WriteLine("MSG: " + s.GetType().Name); }; })) botServer.Wait(); Console.WriteLine("Bot server stopped."); }
public async Task Stop() { using (serverTask) using (tokenSource) { try { tokenSource.Cancel(); await serverTask; } catch (Exception e) { } server = null; serverTask = null; tokenSource = null; options = null; publisherSessionService = null; } }
static async Task test_client_server() { var serverOptions = new RtmpServer.Options { Url = "rtmp://localhost:4000/key", Context = new SerializationContext(), }; using (var server = await RtmpServer.ConnectAsync(serverOptions, x => { })) { var clientOptions = new RtmpClient.Options { Url = "rtmp://localhost:4000/key", Context = new SerializationContext(), }; using (var client = await RtmpClient.ConnectAsync(clientOptions)) { Console.WriteLine("Connect"); } } }
static async void FrameServerAsync() { Console.WriteLine("Frame server starting."); var options = new RtmpServer.Options(); using (frameServer = await RtmpServer.ConnectAsync(options, client => { client.DispatchMessage = s => { if (botClient == null || !botClient.Connected) { return; } if (s is VideoData) { botClient.SendMessage(s); } }; })) frameServer.Wait(); Console.WriteLine("Frame server stopped."); }
public override void Start() { try { string str; IPEndPoint point; if (log.get_IsInfoEnabled()) { log.Info(__Res.GetString("RtmpEndpoint_Start")); } IGlobalScope globalScope = base.GetMessageBroker().GlobalScope; if (FluorineContext.Current != null) { str = Path.Combine(FluorineContext.Current.ApplicationBaseDirectory, "apps"); } else { str = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "apps"); } if (Directory.Exists(str)) { foreach (string str2 in Directory.GetDirectories(str)) { DirectoryInfo info = new DirectoryInfo(str2); string name = info.Name; ApplicationConfiguration appConfig = ApplicationConfiguration.Load(Path.Combine(str2, "app.config")); WebScope scope2 = new WebScope(this, globalScope, appConfig); ScopeContext context = new ScopeContext("/" + name, globalScope.Context.ClientRegistry, globalScope.Context.ScopeResolver, globalScope.Context.ServiceInvoker, null); scope2.Context = context; IScopeHandler handler = ObjectFactory.CreateInstance(appConfig.ApplicationHandler.Type) as IScopeHandler; if (handler == null) { log.Error(__Res.GetString("Type_InitError", new object[] { appConfig.ApplicationHandler.Type })); } scope2.Handler = handler; scope2.SetContextPath("/" + name); scope2.Register(); } } this._rtmpServer = new RtmpServer(this); UriBase uri = base._channelSettings.GetUri(); int port = 0x78f; if ((uri.Port != null) && (uri.Port != string.Empty)) { port = Convert.ToInt32(uri.Port); } if (log.get_IsInfoEnabled()) { log.Info(__Res.GetString("RtmpEndpoint_Starting", new object[] { port.ToString() })); } if (base._channelSettings.BindAddress != null) { point = new IPEndPoint(IPAddress.Parse(base._channelSettings.BindAddress), port); } else { point = new IPEndPoint(IPAddress.Any, port); } this._rtmpServer.AddListener(point); this._rtmpServer.OnError += new ErrorHandler(this.OnError); this._rtmpServer.Start(); if (log.get_IsInfoEnabled()) { log.Info(__Res.GetString("RtmpEndpoint_Started")); } } catch (Exception exception) { if (log.get_IsFatalEnabled()) { log.Fatal("RtmpEndpoint failed", exception); } } }
public PoroServer(PoroServerSettings settings) { _settings = settings; //Create the Authentication Server to handle login requests and client page _auth = new AuthServer(HandleWebServ, _settings.AuthLocations); //Load the certificate store for the RTMPS server var certificateStore = new X509Store(StoreName.Root, StoreLocation.LocalMachine); certificateStore.Open(OpenFlags.MaxAllowed); //Remove last certificate in case it wasn't deleted on close foreach (var cert in certificateStore.Certificates) { if (cert.IssuerName.Name == string.Format("CN={0}", _settings.RTMPSHost)) { certificateStore.Remove(cert); } } //Generate new certificate for this run and add it to the store. var _rtmpsCert = CertGen.CreateSelfSignedCertificate(_settings.RTMPSHost); certificateStore.Add(_rtmpsCert); certificateStore.Close(); //Generate the SerializationContext _context = new SerializationContext(); var structures = Assembly.GetExecutingAssembly().GetTypes().Where(x => String.Equals(x.Namespace, "PoroLib.Structures", StringComparison.Ordinal)); foreach (Type ObjectType in structures) { _context.Register(ObjectType); } //Create the RTMPS server with the context and certificate _server = new RtmpServer(new IPEndPoint(IPAddress.Parse(_settings.RTMPSHost), _settings.RTMPSPort), _context, _rtmpsCert); _server.ClientCommandReceieved += ClientCommandReceieved; _server.ClientMessageReceived += ClientMessageReceived; //Set up the handler _handler = new MessageHandler(); _handler.Register("LoginService"); _handler.Register("MatchmakerService"); _handler.Register("ClientFacadeService"); _handler.Register("InventoryService"); _handler.Register("MasteryBookService"); _handler.Register("SummonerRuneService"); _handler.Register("PlayerPreferencesService"); _handler.Register("LcdsGameInvitationService"); _handler.Register("SummonerTeamService"); //Set up the forwarder _forwarder = new MessageForwarder(_context); //Set up the property redirector _redirector = new PropertyRedirector(_settings); //Set up the data loader _data = new DataLoader(); _redirector.PatcherFound += new PropertyRedirector.PatcherFoundHandler(_data.LoadData); //Set up the user server _users = new UserHandler(); }
public override void Start() { try { if (log.IsInfoEnabled) { log.Info(__Res.GetString(__Res.RtmpEndpoint_Start)); } //Each Application has its own Scope hierarchy and the root scope is WebScope. //There's a global scope that aims to provide common resource sharing across Applications namely GlobalScope. //The GlobalScope is the parent of all WebScopes. //Other scopes in between are all instances of Scope. Each scope takes a name. //The GlobalScope is named "default". //The WebScope is named per Application context name. //The Scope is named per path name. IGlobalScope globalScope = GetMessageBroker().GlobalScope; string baseDirectory; if (FluorineContext.Current != null) { baseDirectory = Path.Combine(FluorineContext.Current.ApplicationBaseDirectory, "apps"); } else { baseDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "apps"); } if (Directory.Exists(baseDirectory)) { foreach (string appDirectory in Directory.GetDirectories(baseDirectory)) { DirectoryInfo directoryInfo = new DirectoryInfo(appDirectory); string appName = directoryInfo.Name; string appConfigFile = Path.Combine(appDirectory, "app.config"); ApplicationConfiguration configuration = ApplicationConfiguration.Load(appConfigFile); WebScope scope = new WebScope(this, globalScope, configuration); // Create context for the WebScope and initialize ScopeContext scopeContext = new ScopeContext("/" + appName, globalScope.Context.ClientRegistry, globalScope.Context.ScopeResolver, globalScope.Context.ServiceInvoker, null); // Store context in scope scope.Context = scopeContext; // ApplicationAdapter IFlexFactory factory = GetMessageBroker().GetFactory(configuration.ApplicationHandler.Factory); FactoryInstance factoryInstance = factory.CreateFactoryInstance(this.Id, null); if (factoryInstance == null) { string msg = string.Format("Missing factory {0}", configuration.ApplicationHandler.Factory); log.Fatal(msg); throw new NotSupportedException(msg); } factoryInstance.Source = configuration.ApplicationHandler.Type; object applicationHandlerInstance = factoryInstance.Lookup(); IScopeHandler scopeHandler = applicationHandlerInstance as IScopeHandler; if (scopeHandler == null) { log.Error(__Res.GetString(__Res.Type_InitError, configuration.ApplicationHandler.Type)); throw new TypeInitializationException(configuration.ApplicationHandler.Type, null); } scope.Handler = scopeHandler; // Make available as "/<directoryName>" and allow access from all hosts scope.SetContextPath("/" + appName); // Register WebScope in server scope.Register(); } } _rtmpServer = new RtmpServer(this); UriBase uri = this.ChannelDefinition.GetUri(); if (uri.Protocol == "http" || uri.Protocol == "https") { log.Info(string.Format("Rtmp endpoint was not started, specified protocol: {0}", uri.Protocol)); return; } int port = 1935; if (uri.Port != null && uri.Port != string.Empty) { try { port = System.Convert.ToInt32(uri.Port); } catch (FormatException ex) { log.Error("Invalid port", ex); return; } } if (log.IsInfoEnabled) { log.Info(__Res.GetString(__Res.RtmpEndpoint_Starting, port.ToString())); } IPEndPoint ipEndPoint; if (this.ChannelDefinition.Properties.BindAddress != null) { IPAddress ipAddress = IPAddress.Parse(this.ChannelDefinition.Properties.BindAddress); ipEndPoint = new IPEndPoint(ipAddress, port); } else { ipEndPoint = new IPEndPoint(IPAddress.Any, port); } _rtmpServer.AddListener(ipEndPoint); _rtmpServer.OnError += new ErrorHandler(OnError); _rtmpServer.Start(); if (log.IsInfoEnabled) { log.Info(__Res.GetString(__Res.RtmpEndpoint_Started)); } } catch (Exception ex) { if (log.IsFatalEnabled) { log.Fatal("RtmpEndpoint failed", ex); } } }
public RtmpServerPacket(RtmpServer server) { mServer = server; }
public Supervisor(RtmpServer server) { this.server = server; }
static void Main(string[] args) { Console.Title = "Draven"; printHeader(); if (!DatabaseManager.DatabaseManager.InitConnection()) { Console.WriteLine("[ERR] Press any Key to exit... (Check your Database Connection)"); Console.ReadKey(); return; } DatabaseManager.DatabaseManager.InitMasteryAndRuneTree(); DatabaseManager.DatabaseManager.InitProfileIcons(); //Create the Authentication Server to handle login requests and client page _auth = new AuthServer.AuthServer(AuthServer.AuthServer.HandleWebServ, AuthLocations); //Load the certificate store for the RTMPS server var certificateStore = new X509Store(StoreName.TrustedPeople, StoreLocation.LocalMachine); certificateStore.Open(OpenFlags.MaxAllowed); //Remove last certificate in case it wasn't deleted on close foreach (var cert in certificateStore.Certificates) { if (cert.IssuerName.Name == $"CN={RTMPSHost}") { certificateStore.Remove(cert); } } //Generate new certificate for this run and add it to the store. var _rtmpsCert = CertGen.CreateSelfSignedCertificate(RTMPSHost); try { certificateStore.Add(_rtmpsCert); certificateStore.Close(); } catch (Exception e) { Console.WriteLine(e); throw new Exception("Faile to create and store the SelfSigned cert to the store."); } //Generate the SerializationContext _context = new SerializationContext(); var structures = Assembly.GetExecutingAssembly().GetTypes().Where(x => isStructureNamespace(x.Namespace)); foreach (Type ObjectType in structures) { _context.Register(ObjectType); $"Successfully registered ({ObjectType.Namespace}) to handler".PrintSuccess(); } //Create the RTMPS server with the context and certificate _server = new RtmpServer(new IPEndPoint(IPAddress.Parse(RTMPSHost), RTMPSPort), _context, _rtmpsCert); _server.ClientCommandReceived += ClientCommandReceieved; _server.ClientMessageReceived += ClientMessageReceived; //Set up the handler _handler = new MessageHandler(); foreach (var service in Services) { try { _handler.Register(service); } catch (Exception e) { $"Failed to register`{service}".PrintError(); e.ToString().PrintError(); } $"Successfully registered ({service}) to handler".PrintSuccess(); } //Set up the property redirector _redirector = new PropertyRedirector(); Console.WriteLine("[LOG] AuthServer listening on port 8080"); _auth.Start(); Console.WriteLine("[LOG] RTMPS Server listening at rtmps://{0}:{1}", RTMPSHost, RTMPSPort); _server.Listen(); while (true) { } }