Example #1
0
        static void Main(string[] args)
        {
            IDictionary props = new Hashtable();

            props["port"] = 0;
            BinaryClientFormatterSinkProvider clientFormatterProvider = new BinaryClientFormatterSinkProvider();
            BinaryServerFormatterSinkProvider serverFormatterProvider = new BinaryServerFormatterSinkProvider();

            serverFormatterProvider.TypeFilterLevel = TypeFilterLevel.Full;
            TcpChannel chan = new TcpChannel(props, clientFormatterProvider, serverFormatterProvider);

            ChannelServices.RegisterChannel(chan, false);
            string clientName = args.Length > 0 ? args[0] : ("client#" + new Random().Next().ToString());
            Client client     = new Client(clientName);

            if (args.Length > 2)
            {
                string uri = args[2];
                ClientCreationNotifier notifier = (ClientCreationNotifier)Activator.GetObject(
                    typeof(ClientCreationNotifier),
                    uri);
                try
                {
                    //System.Diagnostics.Debugger.Break();//---
                    notifier.Notify(client);
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.ToString());
                }
            }

            using (ClientForm clientForm = new ClientForm(client))
            {
                if (args.Length > 1)
                {
                    int       pos    = int.Parse(args[1]);
                    Rectangle screen = Screen.PrimaryScreen.WorkingArea;

                    clientForm.Location = new Point(
                        8 + screen.Left + screen.Width / 2 * (pos & 1),
                        8 + screen.Top + screen.Height / 2 * ((pos & 2) >> 1));
                    //clientForm.Size = new Size(screen.Width/2-16, screen.Height/2-16);
                    clientForm.StartPosition = FormStartPosition.Manual;
                }

                Application.Run(clientForm);
            }
        }
Example #2
0
        public static void Setup()
        {
            if (!channelCreated)
            {
                channelCreated = true;
                IDictionary props = new Hashtable();
                props["port"] = 8086;
                BinaryClientFormatterSinkProvider clientFormatterProvider = new BinaryClientFormatterSinkProvider();
                BinaryServerFormatterSinkProvider serverFormatterProvider = new BinaryServerFormatterSinkProvider();
                serverFormatterProvider.TypeFilterLevel = TypeFilterLevel.Full;
                TcpChannel chan = new TcpChannel(props, clientFormatterProvider, serverFormatterProvider);
                ChannelServices.RegisterChannel(chan, false);
                RemotingConfiguration.RegisterWellKnownServiceType(
                    typeof(ClientCreationNotifier),
                    "ChatClientCreated", WellKnownObjectMode.Singleton);
                chatClientCreatedUri = "tcp://*****:*****@"Chat.TcpServer.exe");
            clientFileName = locateProgram(@"Chat.TcpClient.exe");

            if (isProcessAlive("Chat.TcpServer"))
            {
                killProcess("Chat.TcpServer");
                Thread.Sleep(1000);
                if (isProcessAlive("Chat.TcpServer"))
                {
                    throw new InvalidOperationException("old server still running");
                }
            }

            serverProcess = Process.Start(serverFileName);

            server = (Server)Activator.GetObject(
                typeof(Server),
                "tcp://localhost:8085/ChatServer");
            if (server == null)
            {
                throw new InvalidOperationException("Could not locate server");
            }

            clientProcesses         = new ArrayList();
            clientsEverCreatedCount = 0;
        }