Пример #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            int port = int.Parse(textBox1.Text);
            TcpChannel channel = new TcpChannel(port);
            ChannelServices.RegisterChannel(channel, false);

            RemoteClient rc = new RemoteClient();
            RemotingServices.Marshal(rc, "ChatClient", typeof(RemoteClient));

            server = (ServerInterface)Activator.GetObject(
                typeof(ServerInterface),
                "tcp://localhost:8086/ChatServer");

            try
            {
                server.Connect(port);
            }
            catch (SocketException)
            {
                System.Console.WriteLine("Could not locate server");
            }
        }
Пример #2
0
        static void Main(string[] args)
        {
            try
            {
                RemotingConfiguration.Configure("..\\..\\App.config", true);
                String userName       = args[1];
                String clientUrl      = args[2];
                String serverUrl      = args[3];
                String scriptFileName = args[4];

                Uri clientUri = new Uri(clientUrl);

                BinaryServerFormatterSinkProvider provider = new BinaryServerFormatterSinkProvider();
                IDictionary props = new Hashtable();
                props["port"] = clientUri.Port;
                //props["timeout"] = 10000; // in milliseconds
                TcpChannel channel = new TcpChannel(props, null, provider);

                //TcpChannel channel = new TcpChannel(clientUri.Port);
                ChannelServices.RegisterChannel(channel, false);

                Console.WriteLine(userName);

                ClientImpl MeetingClient = new ClientImpl(userName);
                RemotingServices.Marshal(MeetingClient, clientUri.Segments[1], typeof(ClientImpl));
                ServerInterface server = (ServerInterface)Activator.GetObject(typeof(ServerInterface), serverUrl);
                server.Connect(clientUrl, userName);

                bool         interactive = true;
                StreamReader file        = new StreamReader(scriptFileName);
                string       command     = file.ReadLine();
                Console.Write(" h - imprimir esta ajuda\r\n n - executar o próximo comando\r\n l - imprimir próximo comando\r\n r - correr todos os comandos restantes\r\n");


                while (command != null)
                {
                    if (interactive)
                    {
                        Console.Write("> ");
                        switch (Console.ReadLine())
                        {
                        case "n":
                            Console.WriteLine(command);
                            MeetingClient.ReadCommands(command);
                            command = file.ReadLine();
                            break;

                        case "l":
                            Console.WriteLine(command);
                            break;

                        case "r":
                            interactive = false;
                            break;

                        case "h":
                            Console.Write(" h - imprimir esta ajuda\r\n n - executar o próximo comando\r\n l - imprimir próximo comando\r\n r - correr todos os comandos restantes\r\n");
                            break;
                        }
                    }
                    else
                    {
                        MeetingClient.ReadCommands(command);
                        command = file.ReadLine();
                    }
                }

                file.Close();


                while (true)
                {
                    command = Console.ReadLine();
                    MeetingClient.ReadCommands(command);
                }
            } catch (Exception e)
            {
                Console.WriteLine(e.StackTrace);
                Console.WriteLine(e.Message);
                Console.ReadLine();
            }
        }