Example #1
0
        private bool HandlePush_Ex(PhobosPacket packet)
        {
            //1.二进制传输的消息 直接广播出去
            var bytecmd = packet.Command.GetType() == typeof(ByteNetCommand);

            if (bytecmd)
            {
                NetworkManager.AddEvent(Protocal.Message, (ByteNetCommand)packet.Command);
                return(true);
            }

            var pid = Registry.MustFind(packet.Command.GetType());

            //2. 服务器下推消息
            NetCallback callback = null;

            if (mHandlers.TryGetValue(pid, out callback))
            {
                // 调用回调函数
                callback.Invoke(packet.Head, packet.Command);
                return(true);
            }

            Util.Log($"Push callback not found for: {pid}");
            return(false);
        }
Example #2
0
        /// <summary>
        /// Send data to clients
        /// </summary>
        /// <param name="handler"></param>
        /// <param name="packet"></param>
        public static void Send(PhobosClient handler, PhobosPacket packet)
        {
            byte[] buffer = null; // TODO REWRITE

            for (int i = 0; i < buffer.Length; i += 1024)
            {
                // Begin sending the data to the remote device.
                handler.WorkSocket.BeginSend(buffer, i, buffer.Length <= 1024 ? buffer.Length - i : 1024, 0, SendData, handler.WorkSocket);
            }
        }