Ejemplo n.º 1
0
 public AgNetSession(AgNetPeer peer, EndPoint endPoint)
 {
     this.peer              = peer;
     this.State             = SessionState.Closed;
     this.ClientEndPoint    = endPoint;
     this.LastIncomingData  = DateTime.UtcNow;
     this.reliableChannel   = new AgNetReliableChannel();
     this.unreliableChannel = new AgNetUnreliableChannel();
     this.sequenceChannels  = new Dictionary <int, AgNetSequenceChannel>();
     ResetMtu();
 }
Ejemplo n.º 2
0
        internal void CommitAndEnqueueForSending(OutgoingMessage msg, DeliveryType deliveryType, byte channelIndex)
        {
            if (deliveryType != AgNet.DeliveryType.Reliable && msg.BodyLength > PayloadMTU)
            {
                throw new AgNetException(string.Format("You can't send unreliable messages more than {0} bytes", PayloadMTU));
            }

            if (msg.Sealed)
            {
                throw new AgNetException("This message already has been sent. You can't send one message twice. Please use SendMessage() method with multiple recipients");
            }

            msg.Sealed = true;

            IAgNetChannel channel = GetChannel(deliveryType, channelIndex);

            lock (channel)
            {
                IEnumerable <OutgoingMessage> messages = null;
                if (deliveryType == DeliveryType.Reliable)
                {
                    messages = AgNetReliableChannel.TrySplit(msg, PayloadMTU);
                }
                else
                {
                    messages = new OutgoingMessage[1] {
                        msg
                    }
                };

                foreach (OutgoingMessage splittedMsg in messages)
                {
                    splittedMsg.RemoteEP = ClientEndPoint;
                    channel.CommitMessage(splittedMsg);
                    splittedMsg.Status = AgNetSendStatus.Queued;
                }
            }
        }