예제 #1
0
        //接收数据
        private void ReceiveChatMessage()
        {
            while (true)
            {
                IPEndPoint remote = new IPEndPoint(IPAddress.Any, 0);
                //if (remote == null) continue;
                byte[] data = udpService.Receive(ref remote);
                //if (data == null) continue;
                //解析数据
                ChatMessage msg = ChatMessage.ByteToObject(data);

                //根据消息类型执行相关逻辑

                OnMessageArrived(msg, remote);

                //引发事件
                if (MessageArrived == null)
                {
                    continue;                        //ThreadCrossHelper
                }
                MessageArrivedEventArgs args = new MessageArrivedEventArgs()
                {
                    ArrivedTime = DateTime.Now,
                    Message     = msg
                };
                ThreadCrossHelper.instance.ExecuteOnMainThread(() =>
                {
                    MessageArrived(this, args);
                });
            }
        }
예제 #2
0
        private void DisplayMessage(object sender, MessageArrivedEventArgs e)
        {
            ChatMessageText.text += string.Format("{0}---{1}---{2}\n", DateTime.Now, e.Message.SenderName, e.Message.Content);

            //e.ArrivedTime)+"/n"+
        }
예제 #3
0
 private void DisplayMessage(object sender, MessageArrivedEventArgs e)
 {
     ChatMessageText.text += e.ArrivedTime + "/n" + e.Message.SenderName + "/n" + e.Message.Content;
 }