Ejemplo n.º 1
0
        private void InitializeStream()
        {
            sendStream = NetStream.Create();
            AdvanceLocalSequence();
            var header = WriteHeader();

            reliableWindow.Add(header.ObjSequence, sendStream);
            sendWindow.Add(header.ObjSequence);
            sendWindowTime.Add(header.SendTime);
        }
Ejemplo n.º 2
0
 internal void ForceAck()
 {
     if (sendStream != null)
     {
         return;
     }
     sendStream = NetStream.Create();
     WriteHeader();
     FlushStream();
 }
Ejemplo n.º 3
0
        /// <summary> Attempts to connect to a peer located at the supplied endpoint. </summary>
        public void ConnectToPeer(IPEndPoint endpoint)
        {
            if (EndpointConnected(endpoint) || ConnectingTo(endpoint))
            {
                return;
            }
            NetStream approvalData = NetStream.Create();

            approvalData.WriteByte((byte)ByteCmd.ConnectToPeer);
            Events.WritePeerApproval(endpoint, approvalData);
            Connect(endpoint, approvalData);
        }
Ejemplo n.º 4
0
        /// <summary> Attempts to connect to a server located at the supplied endpoint. </summary>
        public void Connect(IPEndPoint endpoint)
        {
            if (EndpointConnected(endpoint) || connectingEndpoints.Contains(endpoint))
            {
                return;
            }
            NetStream approvalData = NetStream.Create();

            approvalData.WriteByte((byte)ByteCmd.Connect);
            Events.WriteApproval(endpoint, approvalData);
            Connect(endpoint, approvalData);
        }
Ejemplo n.º 5
0
        /// <summary> Receives data until CanReceive is no longer true (receive buffer empty). </summary>
        private void ReceiveAll()
        {
            if (socket == null)
            {
                return;
            }

            while (CanReceive())
            {
                var readStream = NetStream.Create();
                readStream.Socket = this;
                int received = 0;
                if (!TryReceive(readStream.Data, readStream.Data.Length, ref received, ref endPoint))
                {
                    return;
                }
                readStream.Length = received << 3;
                ProcessReceived(endPoint, received, readStream);
            }
        }