Exemplo n.º 1
0
 /// <summary>
 /// Creates the <see cref="T:ExitGames.Net.Sockets.Pgm.PgmSender"/> instances.
 /// </summary>
 private void Initialize()
 {
     for (int i = 0; i < queue.MaxSize; i++)
     {
         PgmSender         sender         = new PgmSender(Address, Port);
         int?              sendBufferSize = null;
         PgmSendWindowSize?windowSize     = null;
         sender.Connect(bindInterface, sendBufferSize, windowSize);
         queue.Enqueue(sender, i);
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Sends a byte array asynchronously.
        /// </summary>
        /// <param name="data">The payload.</param>
        public void Send(byte[] data)
        {
            PgmSender item = queue.Dequeue();

            try
            {
                item.Send(data);
            }
            catch (SocketException exception)
            {
                switch (exception.SocketErrorCode)
                {
                case SocketError.ConnectionReset:
                case SocketError.NotConnected:
                case SocketError.Disconnecting:
                    try
                    {
                        item.Connect(this.bindInterface, null, null);
                    }
                    catch (SocketException exception2)
                    {
                        log.Error("Reconnect failed, " + SocketHelper.FormatSocketException(exception2));
                    }
                    catch (ThreadAbortException)
                    {
                        throw;
                    }
                    catch (OutOfMemoryException)
                    {
                        throw;
                    }
                    catch (Exception exception3)
                    {
                        log.Error("Reconnect failed", exception3);
                    }
                    break;
                }
                throw;
            }
            finally
            {
                queue.Enqueue(item);
            }
        }
Exemplo n.º 3
0
 public PgmSocketSender(string ip, int port, bool sendBatched, int batchSize, PgmSendWindowSize?sendWindowSize, string bindInterface)
 {
     SocketSender = new PgmSender(ip, port);
     if (!string.IsNullOrEmpty(bindInterface))
     {
         IPAddress address;
         if (IPAddress.TryParse(bindInterface, out address))
         {
             bindInterface = address.ToString();
         }
         else
         {
             IPHostEntry entry = Dns.GetHostEntry(bindInterface);
             bindInterface = entry.AddressList[0].ToString();
         }
     }
     PooledSender = new PooledSender(SocketSender, sendBatched, batchSize);
     SocketSender.Connect(bindInterface, null, sendWindowSize);
 }