Пример #1
0
        /// <summary>
        /// 受信コールバック
        /// </summary>
        /// <param name="Result">受信結果</param>
        private void ReceiveCallback(IAsyncResult Result)
        {
            var Sk = Result.AsyncState as Socket;

            var RecvSize = -1;

            try
            {
                RecvSize = Sk.EndReceive(Result);
            }
            catch { return; }

            if (RecvSize > 0)
            {
                MemoryStreamReader     StreamReader = new MemoryStreamReader(Buffer);
                PacketBroadcastMessage Packet       = new PacketBroadcastMessage();
                if (!StreamReader.Serialize(Packet))
                {
                    ChatField.Text += "PACKET SERIALIZE ERROR." + Environment.NewLine;
                    return;
                }

                ChatField.Text += "RECV FROM " + Packet.Uuid + ":" + Packet.Message + Environment.NewLine;
                Sk.BeginReceive(Buffer, 0, BufferSize, SocketFlags.None, ReceiveCallback, Sk);
            }
        }