Exemple #1
0
        /// <summary>
        /// Receive packest from the given network host.
        /// </summary>
        public void GatherPackets(NetworkHost host)
        {
            if (host == null)
            {
                throw new ArgumentNullException("host");
            }

            Packet packet;

            while (host.Receive(out packet))
            {
                // Reconstruct object
                var obj = Serializer.Deserialize(packet.Data);

                TypedPacket <object> typedPacket = new TypedPacket <object>();
                typedPacket.Data       = obj;
                typedPacket.Connection = packet.Connection;
                typedPacket.Channel    = packet.Channel;

                //Debug.LogFormat( "Received a {0} ( {1} bytes )", obj.GetType().Name, packet.Data.Length );

                // If packet type is not yet encountered, created queue for that type.
                if (Queue.ContainsKey(obj.GetType()) == false)
                {
                    Queue[obj.GetType()] = new Queue <TypedPacket <object> >();
                }

                // Add packet object to queue.
                Queue[obj.GetType()].Enqueue(typedPacket);
            }
        }
Exemple #2
0
        /// <summary>
        /// Gets the next available packet of the given type.
        /// </summary>
        public object GetNextPacket(Type type)
        {
            if (HasPacket(type))
            {
                TypedPacket <object> typedPacket = Queue[type].Dequeue();
                return(typedPacket.Data);
            }

            // No packet
            return(null);
        }
Exemple #3
0
        public object GetNextPacket(Type type, out INetworkConnection nwConn)
        {
            if (HasPacket(type))
            {
                TypedPacket <object> typedPacket = Queue[type].Dequeue();
                nwConn = typedPacket.Connection;
                return(typedPacket.Data);
            }

            // No packet
            nwConn = null;
            return(null);
        }