Exemple #1
0
        private void SendReceiveMessage()
        {
            while (true)
            {
                byte[] buffer = null;

                try
                {
                    buffer = client.Receive(ref remoteEp);
                }
                catch (SocketException se)
                {
                    string message = string.Format("HotelHelper2 socket receive error: {0}", se.ErrorCode);
                    util.WriteLog(message);
                }

                if (buffer == null)
                {
                    continue;
                }

                _pms_reg_t msg = util.GetObject <_pms_reg_t>(buffer);

                switch (msg.cmd)
                {
                case STRUCTS.PMS_REGISTER_RES:
                    if (msg.status == STRUCTS.PMS_STATUS_SUCCESS)
                    {
                        this.expires = msg.expires * 1000;
                        this.RegTimerInit();
                        this.IsRegistered = true;
                    }
                    break;

                case STRUCTS.PMS_UNREGISTER_RES:
                    if (msg.status == STRUCTS.PMS_STATUS_SUCCESS)
                    {
                        RegTimerDispose();
                        this.expires      = msg.expires;
                        this.IsRegistered = false;
                    }
                    break;

                default:
                    _pms_data_type pmsmsg = util.GetObject <_pms_data_type>(buffer);

                    if (PassDevice2PmsEvent != null)
                    {
                        PassDevice2PmsEvent(this, pmsmsg);
                    }
                    break;
                }
            }
        }
Exemple #2
0
        public void UnRegister()
        {
            _pms_reg_t _msg = GetMsg(STRUCTS.PMS_UNREGISTER_REQ);

            byte[] _sbuffer = util.GetBytes(_msg);

            try
            {
                client.Send(_sbuffer, _sbuffer.Length);
            }
            catch (SocketException sockex)
            {
                util.WriteLog(sockex.Message);
            }
        }
Exemple #3
0
        public _pms_reg_t GetMsg(int _cmd)
        {
            _pms_reg_t msg = new _pms_reg_t();

            switch (_cmd)
            {
            case STRUCTS.PMS_REGISTER_REQ:
            case STRUCTS.PMS_UNREGISTER_REQ:
                msg.cmd    = _cmd;
                msg.ip     = LOCALIPADDRESS.ToString();
                msg.port   = LOCALPORT;
                msg.status = 0;
                break;
            }
            return(msg);
        }
Exemple #4
0
        public _pms_reg_t GetMsg(int _cmd)
        {
            _pms_reg_t msg = new _pms_reg_t();

            switch (_cmd)
            {
                case STRUCTS.PMS_REGISTER_REQ:
                case STRUCTS.PMS_UNREGISTER_REQ:
                    msg.cmd = _cmd;
                    msg.ip = LOCALIPADDRESS.ToString();
                    msg.port = LOCALPORT;
                    msg.status = 0;
                    break;
            }
            return msg;
        }