Пример #1
0
        internal static DistHead FromHead(_TAG_NETPACK_DISTINGUISHHEAD_VER1 ver1Head)
        {
            DistHead info = new DistHead();

            info.PackType   = ver1Head._packtype;
            info.FollowSize = ver1Head._followsize;
            info.SourceID   = ver1Head._source;
            info.TargetID   = ver1Head._target;
            info.Time       = Helpers.GetTimeFromTimestamp((long)ver1Head._timestamp);
            info.BaseType   = ver1Head._basehead;
            info.BaseSize   = ver1Head._basesize;
            info.ExtType    = ver1Head._exthead;
            info.ExtSize    = ver1Head._extsize;
            info.DataSize   = ver1Head._datasize;
            info.ModuleID   = ver1Head._moduleid;
            info.Number     = ver1Head._number;
            info.Message    = MessageString.FromMessage(ver1Head._message);
            return(info);
        }
Пример #2
0
        private void SendPublishMessage(string msg, MessageString message)
        {
            try
            {
                byte[] byteMsg = Encoding.UTF8.GetBytes(msg);

                NETPACK_BASEHEAD_APPLICATION_VER1 appVer1 = new NETPACK_BASEHEAD_APPLICATION_VER1();
                appVer1._channel  = 0;
                appVer1._encrypt  = (byte)mDataEncrypt;
                appVer1._compress = 0;
                appVer1._format   = (byte)mDataFormat;

                appVer1._datasize  = (ushort)byteMsg.Length;
                appVer1._validsize = Helpers.GetEncryptStoreSize((byte)mDataEncrypt, (ushort)byteMsg.Length);

                _TAG_NETPACK_DISTINGUISHHEAD_VER1 ver1Head = CreateVer1Head(
                    DecDefines.NETPACK_PACKTYPE_APPLICATION,
                    DecDefines.NETPACK_BASETYPE_APPLICATION_VER1,
                    DecDefines.NETPACK_EXTTYPE_NOTHING,
                    appVer1._validsize);

                _TAG_NETPACK_MESSAGE messageMessage = Helpers.CreateMessage(message.SourceModule, message.SourceNumber,
                                                                            message.TargetModule, message.TargetNumber, message.Number, message.SmallType, message.MiddleType,
                                                                            message.LargeType);
                ver1Head._message = messageMessage;

                byte[] byteBaseHead = Converter.Struct2Bytes(appVer1);
                byte[] byteSend     = new byte[byteBaseHead.Length + byteMsg.Length];
                Array.Copy(byteBaseHead, 0, byteSend, 0, byteBaseHead.Length);
                Array.Copy(byteMsg, 0, byteSend, byteBaseHead.Length, byteMsg.Length);
                SendMessage(ver1Head, byteSend);
            }
            catch (Exception ex)
            {
                OnDebug(string.Format("SendMessage fail.\t{0}", ex.Message));
            }
        }
Пример #3
0
 /// <summary>
 /// 创建一个连接器
 /// </summary>
 public DecConnector()
 {
     mHost                   = string.Empty;
     mPort                   = 3072;
     mReceiveBuffer          = new byte[ConstValue.NET_BUFFER_MAX_SIZE];
     mBufferedData           = new byte[ConstValue.NET_BUFFER_MAX_SIZE];
     mBufferedSize           = 0;
     mIsConnected            = false;
     mDistHeadSize           = Marshal.SizeOf(typeof(_TAG_NETPACK_DISTINGUISHHEAD_VER1));
     mIsSubscribeAfterAuthed = false;
     mHearbeatDuration       = 30;
     mRequestID              = 0;
     mEndpointID             = 0;
     mModuleType             = 0;
     mModuleNumber           = 0;
     mDataEncrypt            = 0;
     mDataFormat             = 0;
     mReconnectTime          = 30;
     mIsSSL                  = false;
     mAppName                = string.Format("DEC4Net Demo");
     mMaskMsg                = new MessageString();
     mMessageMsg             = new MessageString();
     GetAppVersion();
 }
Пример #4
0
 /// <summary>
 /// 发布消息
 /// </summary>
 /// <param name="msg"></param>
 /// <param name="message"></param>
 public void PublishMessage(string msg, MessageString message)
 {
     SendPublishMessage(msg, message);
 }
Пример #5
0
 /// <summary>
 /// 订阅消息
 /// </summary>
 /// <param name="mask"></param>
 /// <param name="message"></param>
 public void AddSubscribe(MessageString mask, MessageString message)
 {
     mMaskMsg    = mask;
     mMessageMsg = message;
     SendAddSubscribePackage();
 }