コード例 #1
0
        private void OnClientChatRecived(NetworkMessage netMsg)
        {
            if (InvokeRequired)
            {
                Invoke(new MethodInvoker(() => OnClientChatRecived(netMsg)));
                return;
            }
            ChatMsgPacket packet = netMsg.ReadMessage <ChatMsgPacket>();

            if (packet != null)
            {
                richTextBox1.AppendText(string.Format("[{0}] - [{1}]\n", packet.ClientId, packet.Msg));
            }
            richTextBox1.SelectionStart = richTextBox1.Text.Length;
            richTextBox1.ScrollToCaret();
        }
コード例 #2
0
        private void OnServerGetMsg(NetworkMessage netMsg)
        {
            if (InvokeRequired)
            {
                Invoke(new MethodInvoker(() => OnServerGetMsg(netMsg)));
                return;
            }
            ChatMsgPacket packet = netMsg.ReadMessage <ChatMsgPacket>();

            if (packet != null)
            {
                packet.ClientId = netMsg.conn.connectionId;
                NetworkServer.SendToAll(100, packet);
                richTextBox2.AppendText(string.Format("Client[{0}] sent one msg\n", netMsg.conn.connectionId));
            }
            richTextBox2.SelectionStart = richTextBox2.Text.Length;
            richTextBox2.ScrollToCaret();
        }