Exemplo n.º 1
0
        public void Initialize(Assembly assembly)
        {
            MessageHandler.Instance.Initilize(assembly);
            ProtocolTypeManager.Instance.Initialize();
            MessageReceiver.Instance.Build();
            var config = new JsonConfig();

            config.AddAssemblies(assembly, GetType().GetTypeInfo().Assembly);
            config.InitConfig();
            Init();

            // Init socket
            Cancel = new CancellationTokenSource();

            new IPEndPoint(IPAddress.Parse(Ip), Port).ToListenerObservable(10)
            .ObserveOn(TaskPoolScheduler.Default)
            .Subscribe(
                client =>
            {
                BaseClient baseClient = null;
                client.ToClientObservable(1024)
                .Finally(() => baseClient?.Disconnect())
                .Subscribe(ToClientObserver(client, Cancel.Token, out baseClient), Cancel.Token);
            },
                error => Console.WriteLine("Error: " + error.Message),
                () => Console.WriteLine("Socket Disconnected"),
                Cancel.Token);
        }