コード例 #1
0
        public void MessageRountToEndpoit(byte[] RecieveMessageBytes, int RecieveCount)
        {
            string BaseMessageString;


            BaseMessageString = Encoding.UTF8.GetString(RecieveMessageBytes, 3, RecieveCount - 3);
            string MySrcMobileID    = BaseMessageString.Substring(BaseMessageString.IndexOf("#") + 1, 15);
            string MyDesMobileID    = BaseMessageString.Substring(BaseMessageString.IndexOf("-") + 1, 15);
            string MyCommandMessage = BaseMessageString.Substring(0, BaseMessageString.IndexOf("#"));

            //string MyTimeMarkerStr = string.Format("{0:yyyy-MM-dd HH:mm:ss}", DateTime.Now) + ":" + string.Format("{0:D3}", DateTime.Now.Millisecond);
            string MyTimeMarkerStr = string.Format("{0:HH:mm:ss}", DateTime.Now) + ":" + string.Format("{0:D3}", DateTime.Now.Millisecond);

            //--找移动端通道--------------------------------------------------------------------------------


            FindMobileChannel MyFindMobileChannel = new FindMobileChannel(MyDesMobileID, 10);
            LoginUser         MyLoginUser         = this.MyManagerLoginMobileUser.MyLoginUserList.Find(new Predicate <LoginUser>(MyFindMobileChannel.BindedMobileChannel));

            if (MyLoginUser == null)
            {
                //不存在或者不在线
                this.DisplayResultInfor(1, string.Format("[{0}]对方通道不在线", MyDesMobileID));
                //this.DisplayResultInfor(2, string.Format(MyTimeMarkerStr + "|<-{0}",  BaseMessageString));
                //this.DisplayResultInfor(1, string.Format(MyTimeMarkerStr + "[<-{0}]{1}", ClientSocketEndPointStr, BaseMessageString));
                return;
            }
            else
            {
                //string ClientSocketEndPointStr = MyLoginUser.MyReadWriteSocketChannel.MyTCPClient.Client.LocalEndPoint.ToString();
                //this.DisplayResultInfor(2, string.Format(MyTimeMarkerStr + "[<-{0}]{1}", ClientSocketEndPointStr, BaseMessageString));
            }
            //--再转发出去-----------------------------------------------------------------------------------
            SocketServiceReadWriteChannel MyMobileSocketChannel = MyLoginUser.MyReadWriteSocketChannel;

            if (MyMobileSocketChannel != null)
            {
                byte[] MySendMessageBytes = new byte[RecieveCount];

                for (int i = 0; i < RecieveCount; i++)
                {
                    MySendMessageBytes[i] = RecieveMessageBytes[i];
                }

                StartAsynchSendMessage(MyMobileSocketChannel, MySendMessageBytes);
            }
            else
            {
                this.DisplayResultInfor(1, string.Format(MyTimeMarkerStr + "[{0}]IM转发命令{1}出错!", MyDesMobileID, MyCommandMessage));
            }
        }
コード例 #2
0
        //========================================================================================
        public override void SocketClientResponseCallBack(byte[] RecieveMessageBytes, int RecieveCount)
        {
            string BaseMessageString;

            /*
             * if (RecieveMessageBytes[2] == 254)
             * {
             * BaseMessageString = Encoding.Unicode.GetString(RecieveMessageBytes, 3, RecieveCount - 3);
             * }
             * else
             * {
             * BaseMessageString = Encoding.ASCII.GetString(RecieveMessageBytes, 3, RecieveCount - 3);
             * }
             */

            BaseMessageString = Encoding.UTF8.GetString(RecieveMessageBytes, 3, RecieveCount - 3);
            string MyMobileID       = BaseMessageString.Substring(BaseMessageString.IndexOf("#") + 1, 15);
            string MyLockID         = BaseMessageString.Substring(BaseMessageString.IndexOf("-") + 1, 15);
            string MyCommandMessage = BaseMessageString.Substring(0, BaseMessageString.IndexOf("#"));

            //string MyTimeMarkerStr = string.Format("{0:yyyy-MM-dd HH:mm:ss}", DateTime.Now) + ":" + string.Format("{0:D3}", DateTime.Now.Millisecond);
            string MyTimeMarkerStr         = string.Format("{0:HH:mm:ss}", DateTime.Now) + ":" + string.Format("{0:D3}", DateTime.Now.Millisecond);
            string ClientSocketEndPointStr = MyMobileServerClientAPI.MyTcpClient.Client.LocalEndPoint.ToString();
            //--找移动端通道--------------------------------------------------------------------------------

            /*
             * LGJAsynchSocketService.LockServerLib.FindMobileChannel MyBindedMobileChannel = new LGJAsynchSocketService.LockServerLib.FindMobileChannel(MyMobileID);
             * SocketServiceReadWriteChannel MyReadWriteSocketChannel;
             *
             *
             * try
             * {
             * MyReadWriteSocketChannel = this.MyManagerSocketLoginUser.MyLoginUserList.Find(new Predicate<LoginUser>(MyBindedMobileChannel.SelectMobileChannel)).MyReadWriteSocketChannel;
             * }
             * catch
             * {
             * MyReadWriteSocketChannel = null;
             * }
             */

            FindMobileChannel MyFindMobileChannel = new FindMobileChannel(MyLockID);
            LoginUser         MyLoginUser         = this.MyManagerLoginMobileUser.MyLoginUserList.Find(new Predicate <LoginUser>(MyFindMobileChannel.BindedMobileChannel));

            if (MyLoginUser == null)
            {
                //不存在或者不在线
                this.DisplayResultInfor(1, string.Format("[{0}]所绑定的移动端通道不在线", MyLockID));

                //this.DisplayResultInfor(2, string.Format(MyTimeMarkerStr + "|<-{0}",  BaseMessageString));
                this.DisplayResultInfor(1, string.Format(MyTimeMarkerStr + "[<-{0}]{1}", ClientSocketEndPointStr, BaseMessageString));
                return;
            }
            else
            {
                //this.DisplayResultInfor(2, string.Format(MyTimeMarkerStr + "|<-{0}",  BaseMessageString));
                this.DisplayResultInfor(2, string.Format(MyTimeMarkerStr + "[<-{0}]{1}", ClientSocketEndPointStr, BaseMessageString));
            }
            //下一步处理
            SocketServiceReadWriteChannel MyMobileSocketChannel = MyLoginUser.MyReadWriteSocketChannel;

            //--再转发出去-----------------------------------------------------------------------------------
            if (MyMobileSocketChannel != null)
            {
                byte[] MySendMessageBytes = new byte[RecieveCount];

                for (int i = 0; i < RecieveCount; i++)
                {
                    MySendMessageBytes[i] = RecieveMessageBytes[i];
                }


                StartAsynchSendMessage(MyMobileSocketChannel, MySendMessageBytes);
                //MyTimeMarkerStr = string.Format("{0:MM-dd HH:mm:ss}", DateTime.Now) + ":" + string.Format("{0:D3}", DateTime.Now.Millisecond);
                //MyTimeMarkerStr = string.Format("{0:HH:mm:ss}", DateTime.Now);
                //this.DisplayResultInfor(1, string.Format(MyTimeMarkerStr + " 接收云智能总线[{0}]响应命令:{1}", MyLockID, MyCommandMessage));
            }
            else
            {
                this.DisplayResultInfor(1, string.Format(MyTimeMarkerStr + "[{0}]转发命令{1}出错!", MyLockID, MyCommandMessage));
            }
        }