示例#1
0
 /// <summary>
 /// 接收图片消息
 /// </summary>
 private void RectivePicMessage()
 {
     try
     {
         byte[]   reBuff   = new byte[51000];
         EndPoint endPoint = new IPEndPoint(IPAddress.Any, 44564);
         while (true)
         {
             this.picSocket.ReceiveFrom(reBuff, ref endPoint);
             IPEndPoint end      = endPoint as IPEndPoint;
             string     senderIP = end.Address.ToString();
             if (senderIP == KeyData.StaticInfo.MyUser.IP)
             {
                 continue;
             }
             bool     isPublic = (end.Port == sendProt_Pub);
             HeadBuff head     = GetHead(reBuff);
             if (!Buffers.ContainsKey(head.packKey) && head.packid == 0)
             {
                 ImagePack pack = new ImagePack(head.packKey, head.len, senderIP, isPublic);
                 pack.DownOver += Pack_DownOver;
                 pack.TimeOut  += Pack_TimeOut;
                 Buffers.Add(head.packKey, pack);
             }
             else
             {
                 byte[] soures = new byte[head.len];
                 Array.Copy(reBuff, 24, soures, 0, head.len);
                 Buffers[head.packKey].AddPack(head.packid, soures);
             }
         }
     }
     catch (Exception)
     { }
 }
示例#2
0
            /// <summary>
            /// 返回包头信息
            /// </summary>
            /// <param name="buff"></param>
            /// <returns></returns>
            private HeadBuff GetHead(byte[] buff)
            {
                byte[] key = new byte[16];
                byte[] id  = new byte[4];
                byte[] len = new byte[4];
                Array.Copy(buff, 0, key, 0, 16);
                Array.Copy(buff, 16, id, 0, 4);
                Array.Copy(buff, 20, len, 0, 4);
                HeadBuff head = new HeadBuff()
                {
                    packKey = Encoding.UTF8.GetString(key),
                    packid  = BitConverter.ToInt32(id, 0),
                    len     = BitConverter.ToInt32(len, 0)
                };

                return(head);
            }