/// <summary>
        /// 设备信息接收
        /// </summary>
        /// <param name="o"></param>
        bool Receive()
        {
            PackageToData packageToData = new PackageToData(NewBarVolData);

            //接受设备数据
            try
            {
                byte[]  buffer  = new byte[1024 * 1024];
                int     n       = socket.Receive(buffer);
                Package package = CenterServerNet.BytesToPackage(buffer);
                switch (package.message)
                {
                case Messagetype.package: NewDeviceData(package); return(true);

                case Messagetype.barvolumepackage: NewBarVolData(package); return(true);

                default: return(false);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Data.Live = false;
                return(false);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 设备信息接收
        /// </summary>
        /// <param name="o"></param>
        bool Receive()
        {
            PackageToData packageToData = new PackageToData(NewvolumeData);

            //接受设备数据
            try
            {
                byte[]  buffer  = new byte[1024 * 1024];
                int     n       = socket.Receive(buffer);
                Package package = CenterServerNet.BytesToPackage(buffer);

                switch (package.message)
                {
                case Messagetype.package: NewDeviceData(package); return(true);

                case Messagetype.carinfomessage: packageToData(package); return(true);

                case Messagetype.volumepackage: packageToData(package); return(true);

                default: return(false);
                }
            }
            catch (Exception ex)
            {
                ErrorMessage.GetError(ex);
                Data.Live = false;
                return(false);
            }
        }
Esempio n. 3
0
        void ReceiveCommand(object s)
        {
            Socket command = s as Socket;
            //委托与函数建立联系
            PackageToData packageToData = new PackageToData(NewDeviceData);
            PackageToData packageToCode = new PackageToData(NewCode);
            PackageToData updateToData  = new PackageToData(Updatemessage);

            while (true)
            {
                try
                {
                    byte[] buffer = new byte[1024 * 1024];
                    command.Receive(buffer);
                    Package package = BytesToPackage(buffer);
                    //根据接受的命令去做不同的任务
                    switch (package.message)
                    {
                    case Messagetype.order: packageToCode(package); break;

                    case Messagetype.package: packageToData(package); break;

                    case Messagetype.update: updateToData(package); break;
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    command.Shutdown(SocketShutdown.Both);
                    command.Close();
                    connectflag = true;
                    break;
                }
            }
        }
        /// <summary>
        /// 用户信息接收
        /// </summary>
        /// <param name="o"></param>
        public bool Receive()
        {
            PackageToData packageToData = new PackageToData(NewUserData);

            //接受用户数据
            try
            {
                byte[]  buffer  = new byte[1024 * 1024];
                int     n       = socket.Receive(buffer);
                Package package = CenterServerNet.BytesToPackage(buffer);

                if (package.message == Messagetype.codeus)
                {
                    string receive = Encoding.UTF8.GetString(package.data, 0, package.data.Length);
                    if (receive == "-1")
                    {
                        Send(CenterServerNet.CreatIPListToPackage(Messagetype.codeus, iplist));
                        Console.WriteLine("updatelist");
                        return(false);
                    }
                    else
                    {
                        Data.DeviceID = receive; return(false);
                    }
                }
                else
                {
                    switch (package.message)
                    {
                    case Messagetype.package: packageToData(package, package.message); return(true);

                    case Messagetype.order: NewCode(package); return(true);

                    case Messagetype.update: packageToData(package, package.message); return(true);

                    default: return(false);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Data.Live = false;
                return(false);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// 用户信息接收
        /// </summary>
        /// <param name="o"></param>
        public bool Receive()
        {
            PackageToData packageToData = new PackageToData(NewUserData);

            //接受用户数据
            try
            {
                byte[]  buffer  = new byte[1024 * 1024];
                int     n       = socket.Receive(buffer);
                Package package = CenterServerNet.BytesToPackage(buffer);

                if (package.message == Messagetype.codeus)
                {
                    string receive = Encoding.UTF8.GetString(package.data, 0, package.data.Length);
                    Data.DeviceID = receive;
                    return(false);
                }
                else
                {
                    switch (package.message)
                    {
                    case Messagetype.package: packageToData(package, package.message); return(true);

                    case Messagetype.order: NewCode(package); return(true);

                    case Messagetype.update: packageToData(package, package.message); return(true);

                    default: return(false);
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorMessage.GetError(ex);
                Data.Live = false;
                return(false);
            }
        }