/// <summary>
 /// Initializes a new instance of the ReliableUdpSubscribeObject class using the specified
 /// callback method, message type and ip endpoint.
 /// </summary>
 /// <param name="callback">Callback method to receive messages</param>
 /// <param name="messageType">Message type to receive </param>
 /// <param name="ipEndPoint">Ip endpoint to receive from </param>
 internal ReliableUdpSubscribeObject(ReliableUdpMessageCallback callback,
                                     ReliableUdpMessageTypes messageType = ReliableUdpMessageTypes.Any, IPEndPoint ipEndPoint = null)
 {
     IpEndPoint                 = ipEndPoint;
     ReliableUdpMessageType     = messageType;
     ReliableUdpMessageCallback = callback;
 }
 /// <summary>
 /// Initializes a new instance of the ReliableUdpConnectionRecord
 /// to send message
 /// </summary>
 /// <param name="key">EndPoint and TransmissionId key</param>
 /// <param name="tcb">Connection control block. <see cref="ReliableUdpConnectionControlBlock"/></param>
 /// <param name="reliableUdpMessage"><see cref="ReliableUdpMessage"/> message to send.</param>
 /// <param name="cToken">CancellationToken</param>
 /// <param name="asyncResult"><see cref="AsyncResultSendMessage"/></param>
 /// <exception cref="ArgumentNullException"><paramref name="key"/> or <paramref name="tcb"/> is a null reference</exception>
 public ReliableUdpConnectionRecord(Tuple <EndPoint, Int32> key, ReliableUdpConnectionControlBlock tcb,
                                    ReliableUdpMessage reliableUdpMessage, CancellationToken cToken, AsyncResultSendMessage asyncResult)
     : this(key, tcb)
 {
     if (reliableUdpMessage == null)
     {
         throw new ArgumentNullException("reliableUdpMessage");
     }
     if (reliableUdpMessage.Body == null || reliableUdpMessage.Body.Length == 0)
     {
         throw new ArgumentNullException("reliableUdpMessage", "reliableUdpMessage.Body can not be null.");
     }
     CToken                      = cToken;
     this.AsyncResult            = asyncResult;
     this.ReliableUdpMessageType = reliableUdpMessage.Type;
     this.IsNoAnswerNeeded       = reliableUdpMessage.NoAsk;
     //RU: добавляем содержимое ReliableUdpMessage в словарь ReliableUdpConnectionControlBlock'a
     //EN: fills the array of outcoming message with message bytes
     this.OutcomingStream = Tcb.OutcomingStreams.GetOrAdd(key, reliableUdpMessage.Body);
     //RU: Расчитываем количество пакетов необходимых для отправки сообщения
     this.NumberOfPackets = (int)Math.Ceiling((double)((double)OutcomingStream.Length / (double)this.BufferSize));
     //RU: переключаем состояние на отправку первого пакета
     //EN: set initial state
     this.State = Tcb.States.FirstPacketSending;
 }
 /// <summary>
 /// Initializes a new instance of the ReliableUdpConnectionRecord
 /// to receive message
 /// </summary>
 /// <param name="key">EndPoint and TransmissionId key</param>
 /// <param name="tcb">Connection control block. <see cref="ReliableUdpConnectionControlBlock"/></param>
 /// <param name="reliableUdpMessageType">Type of message to receive</param>
 /// <exception cref="ArgumentNullException"><paramref name="key"/> or <paramref name="tcb"/> is a null reference</exception>
 public ReliableUdpConnectionRecord(Tuple <EndPoint, Int32> key, ReliableUdpConnectionControlBlock tcb,
                                    ReliableUdpMessageTypes reliableUdpMessageType)
     : this(key, tcb)
 {
     CToken = CancellationToken.None;
     this.ReliableUdpMessageType = reliableUdpMessageType;
     //set initial state
     State = Tcb.States.FirstPacketReceived;
 }
        internal static ReliableUdpHeader CreateReliableUdpHeader(Int32 transmissionId,
                                                                  ReliableUdpHeaderFlags flags,
                                                                  ReliableUdpMessageTypes reliableUdpMessageType,
                                                                  Int32 sequenceNumber, Int32 options)
        {
            ReliableUdpHeader header = new ReliableUdpHeader
            {
                TransmissionId         = transmissionId,
                Flags                  = flags,
                ReliableUdpMessageType = reliableUdpMessageType,
                PacketNumber           = sequenceNumber,
                Options                = options,
            };

            return(header);
        }
 /// <summary>
 /// Subscribes for reception of <see cref="ReliableUdpMessage"/> messages
 /// </summary>
 /// <param name="callback">Сallback method to receive messages</param>
 /// <param name="messageType">Message type to receive. Use ReliableUdpMessageTypes.Any
 ///  to receive all messages that comes from specified ip endpoint </param>
 /// <param name="ipEndPoint">Defines from what IP address and port to receive messages.
 /// Set IPEndPoint.Port property in 0 for obtaining messages from any port of the specified address.
 /// Set <c>null</c> to receive messages from any ip endpoint </param>
 /// <returns><see cref="ReliableUdpSubscribeObject"/>. Represents a subscriber.</returns>
 internal ReliableUdpSubscribeObject SubscribeOnMessages(ReliableUdpMessageCallback callback,
                                                         ReliableUdpMessageTypes messageType, IPEndPoint ipEndPoint)
 {
     try
     {
         System.Threading.Monitor.Enter(m_locker);
         ReliableUdpSubscribeObject subscribe = new ReliableUdpSubscribeObject(callback, messageType, ipEndPoint);
         if (m_subscribers.Contains(subscribe))
         {
             return(m_subscribers[m_subscribers.IndexOf(subscribe)]);
         }
         m_subscribers.Add(subscribe);
         return(subscribe);
     }
     finally
     {
         System.Threading.Monitor.Exit(m_locker);
     }
 }
Esempio n. 6
0
 /// <summary>
 /// Initializes a new instance of the ReliableUdpMessage 
 /// </summary>
 /// <param name="messageTypes">Type of the message</param>
 /// <param name="body">Message body (in bytes)</param>
 /// <param name="noAsk">Not to use the mechanism of reliable delivery.</param>
 public ReliableUdpMessage(ReliableUdpMessageTypes messageTypes, byte[] body, bool noAsk = false)
 {
     this.Type = messageTypes;
       this.Body = body;
       this.NoAsk = noAsk;
 }
 /// <summary>
 /// Subscribes for reception of <see cref="ReliableUdpMessage"/> messages
 /// </summary>
 /// <param name="callback">Сallback method to receive messages</param>
 /// <param name="messageType">Message type to receive. Use ReliableUdpMessageTypes.Any
 ///  to receive all messages that comes from specified ip endpoint </param>
 /// <param name="ipEndPoint">Defines from what IP address and port to receive messages. 
 /// Set IPEndPoint.Port property in 0 for obtaining messages from any port of the specified address.
 /// Set <c>null</c> to receive messages from any ip endpoint </param>
 /// <returns><see cref="ReliableUdpSubscribeObject"/>. Represents a subscriber.</returns>
 internal ReliableUdpSubscribeObject SubscribeOnMessages(ReliableUdpMessageCallback callback,
     ReliableUdpMessageTypes messageType, IPEndPoint ipEndPoint)
 {
     try
       {
     System.Threading.Monitor.Enter(m_locker);
     ReliableUdpSubscribeObject subscribe = new ReliableUdpSubscribeObject(callback, messageType, ipEndPoint);
     if (m_subscribers.Contains(subscribe))
     {
       return m_subscribers[m_subscribers.IndexOf(subscribe)];
     }
     m_subscribers.Add(subscribe);
     return subscribe;
       }
       finally
       {
     System.Threading.Monitor.Exit(m_locker);
       }
 }
Esempio n. 8
0
 /// <summary>
 /// Subscribes for reception of <see cref="ReliableUdpMessage"/> messages
 /// </summary>
 /// <param name="callback">Сallback method to receive messages</param>
 /// <param name="messageType">Message type to receive. Use ReliableUdpMessageTypes.Any
 ///  to receive all messages that comes from specified ip endpoint </param>
 /// <param name="ipEndPoint">Defines from what IP address and port to receive messages. 
 /// Set IPEndPoint.Port property in 0 for obtaining messages from any port of the specified address.
 /// Set <c>null</c> to receive messages from any ip endpoint </param>
 /// <returns><see cref="ReliableUdpSubscribeObject"/>. Represents a subscriber.</returns>
 public ReliableUdpSubscribeObject SubscribeOnMessages(ReliableUdpMessageCallback callback,
                                                   ReliableUdpMessageTypes messageType =
                                                     ReliableUdpMessageTypes.Any, IPEndPoint ipEndPoint = null)
 {
     return m_tcb.SubscribeOnMessages(callback, messageType, ipEndPoint);
 }
Esempio n. 9
0
 internal static ReliableUdpHeader CreateReliableUdpHeader(Int32 transmissionId,
                                                       ReliableUdpHeaderFlags flags,
                                                       ReliableUdpMessageTypes reliableUdpMessageType,
                                                       Int32 sequenceNumber, Int32 options)
 {
     ReliableUdpHeader header = new ReliableUdpHeader
                            {
                              TransmissionId = transmissionId,
                              Flags = flags,
                              ReliableUdpMessageType = reliableUdpMessageType,
                              PacketNumber = sequenceNumber,
                              Options = options,
                            };
       return header;
 }
Esempio n. 10
0
 /// <summary>
 /// Initializes a new instance of the ReliableUdpMessage
 /// </summary>
 /// <param name="messageTypes">Type of the message</param>
 /// <param name="body">Message body (in bytes)</param>
 /// <param name="noAsk">Not to use the mechanism of reliable delivery.</param>
 public ReliableUdpMessage(ReliableUdpMessageTypes messageTypes, byte[] body, bool noAsk = false)
 {
     this.Type  = messageTypes;
     this.Body  = body;
     this.NoAsk = noAsk;
 }
 /// <summary>
 /// Initializes a new instance of the ReliableUdpConnectionRecord
 /// to receive message 
 /// </summary>
 /// <param name="key">EndPoint and TransmissionId key</param>
 /// <param name="tcb">Connection control block. <see cref="ReliableUdpConnectionControlBlock"/></param>
 /// <param name="reliableUdpMessageType">Type of message to receive</param>
 /// <exception cref="ArgumentNullException"><paramref name="key"/> or <paramref name="tcb"/> is a null reference</exception>
 public ReliableUdpConnectionRecord(Tuple<EndPoint, Int32> key, ReliableUdpConnectionControlBlock tcb,
                                ReliableUdpMessageTypes reliableUdpMessageType)
     : this(key, tcb)
 {
     CToken = CancellationToken.None;
       this.ReliableUdpMessageType = reliableUdpMessageType;
       //set initial state
       State = Tcb.States.FirstPacketReceived;
 }
Esempio n. 12
0
 /// <summary>
 /// Subscribes for reception of <see cref="ReliableUdpMessage"/> messages
 /// </summary>
 /// <param name="callback">Сallback method to receive messages</param>
 /// <param name="messageType">Message type to receive. Use ReliableUdpMessageTypes.Any
 ///  to receive all messages that comes from specified ip endpoint </param>
 /// <param name="ipEndPoint">Defines from what IP address and port to receive messages.
 /// Set IPEndPoint.Port property in 0 for obtaining messages from any port of the specified address.
 /// Set <c>null</c> to receive messages from any ip endpoint </param>
 /// <returns><see cref="ReliableUdpSubscribeObject"/>. Represents a subscriber.</returns>
 public ReliableUdpSubscribeObject SubscribeOnMessages(ReliableUdpMessageCallback callback,
                                                       ReliableUdpMessageTypes messageType =
                                                       ReliableUdpMessageTypes.Any, IPEndPoint ipEndPoint = null)
 {
     return(m_tcb.SubscribeOnMessages(callback, messageType, ipEndPoint));
 }