示例#1
0
文件: Client.cs 项目: bvalente/dad
        static void Main()
        {
            TcpChannel channel = new TcpChannel();

            ChannelServices.RegisterChannel(channel, false);

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

            try{
                Console.WriteLine(server.Ping());
            } catch (SocketException) {
                System.Console.WriteLine("socket error");
            }

            //end of file
            Console.ReadLine();
        }
示例#2
0
        public void Connect(Object sender, RoutedEventArgs e)
        {
            string port = portBox.Text;
            string nick = nickBox.Text;
            string url  = "tcp://localhost:" + port + "/ClientChat";

            //create connection
            TcpChannel channel = new TcpChannel(Int32.Parse(port));

            ChannelServices.RegisterChannel(channel, false);

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

            try{
                //Console.WriteLine(server.Ping());
                serverBlock.Text = server.Ping();
            } catch (SocketException e) {
                System.Console.WriteLine("socket error");
            }

            //marshal client chat

            client = new ClientChat(this);
            RemotingServices.Marshal(
                client,
                "ClientChat",
                typeof(ClientChat));

            //send info to server
            server.AddUser(nick, url); //catch exception?

            portBox.IsEnabled       = false;
            nickBox.IsEnabled       = false;
            connectButton.IsEnabled = false;
        }