/// <summary>

        /// 监听客户端连接

        /// </summary>
        //接受并监听客户端
        private static void ListenClientConnect(object CameraNo)

        {
            int CameraNum = (int)CameraNo;

            while (true)

            {
                try
                {
                    Socket clientSocket = serverSocket[CameraNum].Accept();

                    //clientSocket.Send(Encoding.ASCII.GetBytes("Server Say Hello"));
                    //if (System.Convert.ToBoolean(clientSocket.Available))
                    //{
                    Thread receiveThread = new Thread(ReceiveMessage);

                    ReciveMessageParam param = new ReciveMessageParam();

                    param.CameraNum = CameraNum;

                    param.clientSocket = clientSocket;

                    receiveThread.Start(param);

                    Thread.Sleep(5);
                }
                catch (System.ArgumentNullException)
                {
                    return;
                }
                catch (System.InvalidOperationException)
                {
                    return;
                }
            }
        }
        /// <summary>

        /// 接收消息

        /// </summary>

        /// <param name="clientSocket"></param>

        private static void ReceiveMessage(object obj)

        {
            ReciveMessageParam param = (ReciveMessageParam)obj;

            int CameraNum = param.CameraNum;

            Socket myClientSocket = param.clientSocket;

            int recievenum = 1;

            int packagepick = 0;

            //通过clientSocket接收数据
            List <byte> resultadd = new List <byte>();

            byte[] result = new byte[Packagebag];

            while (true)

            {
                try

                {
                    // while (System.Convert.ToBoolean(myClientSocket.Available))
                    //{
                    // int receiveNumber = myClientSocket.Receive(result);
                    //Console.WriteLine("111")
                    //}
                    //while (recievenum != 0)
                    //{

                    byte[] resultonce = new byte[300000];

                    recievenum = myClientSocket.Receive(resultonce);

                    //判断读出的为新字节
                    if (recievenum != 0)
                    {
                        resultadd.AddRange(resultonce);
                        packagepick = packagepick + recievenum;
                    }


                    //for (int i = packagepick; i < packagepick + recievenum; i++)
                    //{
                    //    resultadd[i] = resultonce[i-packagepick];
                    //}


                    //总字节数超过一包
                    if (packagepick >= Packagebag)
                    {
                        //得出所在包数据
                        result = resultadd.ToArray().Skip(0).Take(Packagebag).ToArray();
                        //其后数据迁移
                        byte[] Exchange = resultadd.ToArray().Skip(Packagebag).Take(packagepick - Packagebag).ToArray();

                        packagepick = packagepick - Packagebag;

                        resultadd.Clear();
                        resultadd.AddRange(Exchange);

                        Thread DrawImageThread = new Thread(DrawPixelImage);

                        DrawImageParam dparam = new DrawImageParam();

                        dparam.CameraNum = CameraNum;

                        dparam.imagesource = (byte[])result.Clone();

                        DrawImageThread.Start(dparam);
                        // SockPack SockPicture = new SockPack();
                        // SockPicture = (SockPack)BytesToStruct(result, SockPicture.GetType());


                        // Console.WriteLine("{0}帧图像,第一个像素值为{1},最后一个像素值为{2}", SockPicture.Framecnt.ToString(), SockPicture.Picture[0].ToString(), SockPicture.Picture[259 * 205 - 1].ToString());
                    }


                    Thread.Sleep(5);

                    //Console.WriteLine("接收客户端{0}消息{1}", myClientSocket.RemoteEndPoint.ToString(), Encoding.UTF8.GetString(result, 0, receiveNumber));



                    //Console.WriteLine("接收客户端{0}消息{1}", myClientSocket.RemoteEndPoint.ToString(), result);
                }

                catch (Exception ex)

                {
                    Console.WriteLine(ex.Message);

                    myClientSocket.Shutdown(SocketShutdown.Both);

                    myClientSocket.Close();

                    break;
                }
            }
        }