Exemplo n.º 1
0
        static void Main(string[] args)
        {
            var host = "localhost";
            var port = 4099;

            Console.WriteLine("<Please enter the name...>");
            var name = Console.ReadLine();

            var client = new ChatRoomClient(host, port);

            client.Receive += (sender, eventArgs) =>
            {
                Console.WriteLine($"{eventArgs.Message.Name} sad: {eventArgs.Message.Text}");
            };
            client.Connect();

            client.SendName(name);

            Console.WriteLine("輸入字串可以送出訊息");

            while (true)
            {
                var text = Console.ReadLine();
                client.SendMessage(text);

                Console.WriteLine($"訊息: {text} 已送出!");
            }
        }
Exemplo n.º 2
0
        public ChatRoom()
        {
            InitializeComponent();

            if (DesignerProperties.GetIsInDesignMode(this))
            {
                return;
            }

            _client.Connect();
        }
Exemplo n.º 3
0
    public void Connect(string host, int port, string name)
    {
        m_Client = new ChatRoomClient(host, port);

        m_Client.Connect();

        var syncContext = SynchronizationContext.Current;

        m_ClientReceiveEventSubscribe = Observable.FromEventPattern <ChatMessageEventArgs>(
            h => m_Client.Receive    += h,
            h => m_Client.Receive    -= h)
                                        .Subscribe(e =>
        {
            syncContext.Post(state => Receive?.Invoke(this, e.EventArgs), null);
        });

        m_Client.SendName(name);
    }