예제 #1
0
        private static void MainLifetime(string[] args, LifetimeDefinition lifetimeDefinition)
        {
            var lifetime = lifetimeDefinition.Lifetime;

            var reflectionSerializers = new ReflectionSerializersFacade();
            var serializers           = new Serializers(reflectionSerializers.Registrar);

            var      scheduler = SingleThreadScheduler.RunOnSeparateThread(lifetime, "Scheduler");
            Protocol protocol;

            SocketWire.Base wire;


            var isServer = args.Length == 0 ? Util.Fork(args) : args[0] == "server";

            if (isServer)
            {
                Console.Title = "Server";
                wire          = new SocketWire.Server(lifetime, scheduler, ourIpEndPoint);
                protocol      = new Protocol("Server", serializers, new Identities(IdKind.Server), scheduler, wire, lifetime);
            }
            else
            {
                Console.Title = "Client";
                wire          = new SocketWire.Client(lifetime, scheduler, ourIpEndPoint);
                protocol      = new Protocol("Client", serializers, new Identities(IdKind.Client), scheduler, wire, lifetime);
            }

            scheduler.Queue(() => RunApplication(isServer, reflectionSerializers, lifetime, protocol));

            wire.Connected.Change.Advise(lifetime, value =>
            {
                if (value)
                {
                    Console.Title += ": connected";
                }
                else
                {
                    lifetimeDefinition.Terminate();
                }
            });

            while (lifetime.IsAlive)
            {
                if (Console.KeyAvailable && OnChar != null)
                {
                    scheduler.Queue(() => OnChar?.Invoke(Console.ReadKey(true).KeyChar));
                }

                Thread.Sleep(100);
            }
        }
예제 #2
0
 private void Form_KeyPress(object sender, KeyPressEventArgs e)
 {
     OnChar?.Invoke(e.KeyChar);
 }