コード例 #1
0
 public void Connect(string sendInterface, int?sendBufferSize, PgmSendWindowSize?windowSize)
 {
     lock (syncRoot)
     {
         if (socket != null)
         {
             socket.Close();
             socket = null;
         }
         socket = new PgmSocket();
         int?nullable = sendBufferSize;
         socket.SendBufferSize = nullable.HasValue ? nullable.GetValueOrDefault() : 0x100000;
         if (!string.IsNullOrEmpty(sendInterface))
         {
             IPAddress interfaceIpAddress = IPAddress.Parse(sendInterface);
             this.socket.SetSendInterface(interfaceIpAddress);
         }
         socket.Bind(new IPEndPoint(IPAddress.Any, 50001));
         if (!windowSize.HasValue)
         {
             windowSize = new PgmSendWindowSize(DefaultRateKbitsPerSec, DefaultWindowSizeInMSecs, DefaultWindowSizeInBytes);
         }
         socket.SetSendWindowSize(windowSize.Value);
         socket.Connect(EndPoint);
     }
 }
コード例 #2
0
 /// <summary>
 /// Starts the listening.
 /// </summary>
 ///             <exception cref="T:System.InvalidOperationException">
 ///        Already running.
 ///     </exception>
 ///     <exception cref="T:System.Net.Sockets.SocketException">
 ///      Exception from the underlying <see cref="T:System.Net.Sockets.Socket"/>.
 ///     </exception>
 public void Start()
 {
     try
     {
         lock (_lock)
         {
             if (running)
             {
                 throw new InvalidOperationException("Listener is allready started.");
             }
             socket = new PgmSocket()
             {
                 ReceiveBufferSize = receiveBufferSize
             };
             socket.SetReuseAddress(ReuseAddress);
             socket.Bind(LocalEndPoint);
             socket.AddReceiveInterfaces(receiveInterfaces);
             if (UseHighSpeedIntranet)
             {
                 socket.SetHighSpeedIntranetOption(UseHighSpeedIntranet);
             }
             socket.Listen(5);
             socketAsyncEventArgs            = new SocketAsyncEventArgs();
             socketAsyncEventArgs.Completed += new EventHandler <SocketAsyncEventArgs>(OnAcceptAsyncCompleted);
             running = true;
         }
         BeginAccept();
         if (log.IsDebugEnabled)
         {
             log.DebugFormat("Listening on {0}", LocalEndPoint);
         }
     }
     catch (ThreadAbortException)
     {
         throw;
     }
     catch (OutOfMemoryException)
     {
         throw;
     }
     catch (SocketException exception)
     {
         if (log.IsErrorEnabled)
         {
             log.Error(SocketHelper.FormatSocketException(exception), exception);
         }
         throw;
     }
 }