コード例 #1
0
        public override void OnMessage(USocket us, ByteBuf bb)
        {
            bb.ReaderIndex(us.getProtocal().HeaderLen());
            short cmd = bb.ReadShort();

            byte[] bs = bb.GetRaw();
            Statics.SetXor(bs, bb.ReaderIndex());
            MemoryStream stream  = new MemoryStream(bs, bb.ReaderIndex(), bb.ReadableBytes());
            object       obj     = ProtoBuf.Serializer.NonGeneric.Deserialize(MessageQueueHandler.GetProtocolType(cmd), stream);
            FieldInfo    success = obj.GetType().GetField("success");

            if (success != null)
            {
                if ((bool)success.GetValue(obj) == true)
                {
                    MessageQueueHandler.PushQueue(cmd, obj);
                }
                else
                {
                    FieldInfo info = obj.GetType().GetField("info");
                    if (info != null)
                    {
                        Debug.LogWarning("下行出错, cmd=" + cmd + ", type=" + MessageQueueHandler.GetProtocolType(cmd).ToString());
                        MessageQueueHandler.PushError(info.GetValue(obj).ToString());
                    }
                }
            }
        }
コード例 #2
0
        private void AddMessageQueueToNodes(Channel channel)
        {
            var node1 = GetNodeById(channel.FirstNodeId);
            var node2 = GetNodeById(channel.SecondNodeId);

            var firstMessageQueue  = new MessageQueueHandler(channel.Id);
            var secondMessageQueue = new MessageQueueHandler(channel.Id);

            node1.MessageQueueHandlers.Add(firstMessageQueue);
            node2.MessageQueueHandlers.Add(secondMessageQueue);
        }
コード例 #3
0
        public Frame EncodeMessage <TIn>(SocketRequestMessage <TIn> message)
        {
            byte[] data = Serialize.Serialize(message.Data);
            Debug.Log("SocketRequest Request: " + message.Data);
            Frame f = new Frame(512);

            f.PutShort(MessageQueueHandler.GetProtocolCMD(message.GetType()));
            byte[] encryptedData = Crypto.Encryption(data);
            f.PutBytes(encryptedData);
            f.End();
            return(f);
        }
コード例 #4
0
        public override void OnMessage(USocket us, ByteBuf bb)
        {
            bb.ReaderIndex(us.getProtocol().HeaderLen());
            short cmd = bb.ReadShort();

            byte[] bs = bb.GetRaw();
            using (var stream = new MemoryStream(bs, bb.ReaderIndex(), bb.ReadableBytes()))
            {
                object obj = protocol.DecodeMessage(MessageQueueHandler.GetProtocolType(cmd), stream);
                MessageQueueHandler.PushQueue(cmd, obj);
            }
        }
コード例 #5
0
        private void Send()
        {
            StringBuilder bld = new StringBuilder();

            for (int i = 0; i < cmd.Length; i++)
            {
                bld.Append(cmd[i]);
                bld.Append(" ");
            }

            MessageQueueHandler.AddMessage(Model.PeerMgr.GetPeer(), bld.ToString());
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: IGDA-SD/DiasporaProjectVR
        static void Main(string[] args)
        {
            NtpSyncModule ntpSync = new NtpSyncModule("pool.ntp.org");

            ntpSync.GetNetworkTime();
            if (ntpSync.SyncedTime.HasValue)
            {
                Console.WriteLine("Synced time test: " + ntpSync.SyncedTime.Value);
            }

            MessageQueueHandler mHandler = new MessageQueueHandler();

            mHandler.Run();
        }
コード例 #7
0
        public override void OnMessage(USocket us, ByteBuf bb)
        {
            bb.ReaderIndex(us.getProtocol().HeaderLen());
            int cmd = bb.ReadInt();

            Debug.Log("Socket Recive Message ID: " + cmd);
            byte[] bs = bb.GetRaw();
            using (var stream = new MemoryStream(bs, bb.ReaderIndex(), bb.ReadableBytes()))
            {
                if (MessageQueueHandler.GetProtocolType(cmd) != null)
                {
                    object obj = protocol.DecodeMessage(MessageQueueHandler.GetProtocolType(cmd), stream);
                    MessageQueueHandler.PushQueue((short)cmd, obj);
                }
            }
        }
コード例 #8
0
        public Frame EncodeMessage <TIn>(SocketRequestMessage <TIn> message)
        {
            var type           = message.GetType();
            var protoAttribute = Attribute.GetCustomAttribute(type, typeof(ProtoAttribute), false) as ProtoAttribute;

            Debug.Log($"SocketRequest Request: MessageID: {protoAttribute.value} {protoAttribute.description}, MessageData: {message.Data.ToString()}");
            byte[] data = Serialize.Serialize(message.Data);

            Frame f = new Frame32(512);

            f.PutInt(MessageQueueHandler.GetProtocolCMD(message.GetType()));
            byte[] encryptedData = Crypto.Encryption(data);
            f.PutBytes(encryptedData);
            f.End();
            return(f);
        }
コード例 #9
0
ファイル: SocketTest.cs プロジェクト: zhanghuiyu/cocosocket
    private void Send(object param)
    {
        MemoryStream stream = new MemoryStream();

        ProtoBuf.Serializer.NonGeneric.Serialize(stream, param);
        byte[] bs = stream.ToArray();
        Frame  f  = null;

        if (socket.getProtocal().GetType() == typeof(Varint32HeaderProtocol))
        {
            f = new Varint32Frame(512);
        }
        else
        {
            f = new Frame(512);
        }
        f.PutShort(MessageQueueHandler.GetProtocolCMD(param.GetType()));
        Debug.LogWarning("上行 cmd=" + MessageQueueHandler.GetProtocolCMD(param.GetType()) + ", type=" + param.GetType().ToString() + ", " + Time.fixedTime);
        Statics.SetXor(bs);
        f.PutBytes(bs);
        f.End();
        socket.Send(f);
    }
コード例 #10
0
        public static void Main(String[] args)
        {
            // Activate debug mode in console output
            //Common.IO.Console.VERBOSE_LEVEL = 2;

            // Start listener for new clients
            IPAddress ipAddr = IPAddress.Parse(IP);
            Listener  server = new Listener(SERVER_NAME, ipAddr, PORT);

            Model.Listener = server;
            server.Start();

            // Start message queue handler for sending data
            MessageQueueHandler mqh = new MessageQueueHandler(MessageQueueHandler.INTERVAL);

            Model.MessageQueueHandler = mqh;
            mqh.Start();

            // Start listener for user input
            UserInputListener uiListener = new UserInputListener(new IO.CommandInputHandler());

            uiListener.Start();
            Model.UserInputListener = uiListener;
        }
コード例 #11
0
 /**
  *
  */
 public override void OnClose(USocket us, bool fromRemote)
 {
     MessageQueueHandler.PushError(fromRemote ? "与服务器连接已断开" : "关闭连接");
 }