System.Net.Sockets.Socket.InternalBind C# (CSharp) Method

InternalBind() private method

private InternalBind ( EndPoint localEP ) : void
localEP EndPoint
return void
        internal void InternalBind(EndPoint localEP)
        {
            if (NetEventSource.IsEnabled) NetEventSource.Enter(this, localEP);

            if (CleanedUp)
            {
                throw new ObjectDisposedException(GetType().FullName);
            }

            if (NetEventSource.IsEnabled) NetEventSource.Info(this, $"localEP:{localEP}");

            if (localEP is DnsEndPoint)
            {
                NetEventSource.Fail(this, "Calling InternalBind with a DnsEndPoint, about to get NotImplementedException");
            }

            // Ask the EndPoint to generate a SocketAddress that we can pass down to native code.
            EndPoint endPointSnapshot = localEP;
            Internals.SocketAddress socketAddress = SnapshotAndSerialize(ref endPointSnapshot);
            DoBind(endPointSnapshot, socketAddress);

            if (NetEventSource.IsEnabled) NetEventSource.Exit(this);
        }

Usage Example

 private void BindUsingDelegate(Socket socket, IPEndPoint remoteIPEndPoint)
 {
     IPEndPoint remoteEndPoint = new IPEndPoint(remoteIPEndPoint.Address, remoteIPEndPoint.Port);
     int retryCount = 0;
     while (retryCount < 0x7fffffff)
     {
         IPEndPoint localEP = this.BindIPEndPointDelegate(this, remoteEndPoint, retryCount);
         if (localEP == null)
         {
             break;
         }
         try
         {
             socket.InternalBind(localEP);
             break;
         }
         catch
         {
         }
         retryCount++;
     }
     if (retryCount == 0x7fffffff)
     {
         throw new OverflowException("Reached maximum number of BindIPEndPointDelegate retries");
     }
 }
All Usage Examples Of System.Net.Sockets.Socket::InternalBind