Ejemplo n.º 1
0
        protected BMSByte ReadBuffer(NetworkStream stream)
        {
            int count = 0;

            while (stream.DataAvailable)
            {
                previousSize = backBuffer.Size;
                backBuffer.SetSize(backBuffer.Size + 1024);

                count += stream.Read(backBuffer.byteArr, previousSize, 1024);
                backBuffer.SetSize(previousSize + count);
            }

            int size = BitConverter.ToInt32(backBuffer.byteArr, backBuffer.StartIndex());

            readBuffer.Clear();

            if (count == 0)
            {
                return(readBuffer);
            }

            readBuffer.BlockCopy(backBuffer.byteArr, backBuffer.StartIndex(4), size);

            if (readBuffer.Size + 4 < backBuffer.Size)
            {
                backBuffer.RemoveStart(size + 4);
            }
            else
            {
                backBuffer.Clear();
            }

            return(readBuffer);
        }
Ejemplo n.º 2
0
        public BMSByte Receive(ref IPEndPoint remoteEP, ref string endpoint)
        {
            CheckDisposed();

            recBuffer.Clear();

            if (endPoint == null)
            {
                endPoint = new IPEndPoint(IPAddress.Any, 0);
            }

            int dataRead = socket.ReceiveFrom(recBuffer.byteArr, ref endPoint);

            if (!connections.ContainsKey(endPoint))
            {
                connections.Add(endPoint, (((IPEndPoint)endPoint).Address.ToString() + HOST_PORT_CHARACTER_SEPARATOR + ((IPEndPoint)endPoint).Port.ToString()));
            }

            endpoint = connections[endPoint];

            //if (dataRead < recBuffer.Size)
            //	recBuffer = CutArray(recBuffer, dataRead);

            recBuffer.SetSize(dataRead);

            remoteEP = (IPEndPoint)endPoint;
            return(recBuffer);
        }
        /// <summary>
        /// Constructor for the NetworkingStream with a passed in stream
        /// </summary>
        /// <param name="stream">The stream passed in to be used</param>
        public NetworkingStreamRPC(NetworkingStream stream, bool skipCall = false)
        {
            FailedExecution = false;

            // TODO:  Check for null NetworkedBehavior or if it is the base class
            if (!skipCall && ReferenceEquals(stream.NetworkedBehavior, null))
            {
                return;
            }

#if NETFX_CORE
            var properties = stream.GetType().GetRuntimeProperties();
#else
            var properties = stream.GetType().GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
#endif
            foreach (PropertyInfo property in properties)
            {
                //if (property.PropertyType == typeof(BMSByte))
                //	continue;

                if (property.CanRead && property.CanWrite)
                {
                    property.SetValue(this, property.GetValue(stream, null), null);
                }
            }

            if (!skipCall)
            {
                FailedExecution = !NetworkedBehavior.InvokeRPC(this);
            }
            else
            {
                Bytes = new BMSByte().Clone(stream.Bytes.byteArr, stream.Bytes.byteArr.Length - 1);
                Bytes.MoveStartIndex(stream.Bytes.StartIndex());
                Bytes.SetSize(stream.Bytes.Size);
            }
        }