Share via


Bind Method

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

Associates a Socket with a local endpoint.

Namespace:  System.Net.Sockets
Assembly:  System (in System.dll)

Syntax

'Declaration
Public Sub Bind ( _
    localEP As EndPoint _
)
public void Bind(
    EndPoint localEP
)
public:
void Bind(
    EndPoint^ localEP
)
member Bind : 
        localEP:EndPoint -> unit 
public function Bind(
    localEP : EndPoint
)

Parameters

Remarks

Use the Bind method if you need to use a specific local endpoint. You must call Bind before you can call the Listen method. You do not need to call Bind before using the Connect method unless you need to use a specific local endpoint. You can use the Bind method on both connectionless and connection-oriented protocols.

Before calling Bind, you must first create the local IPEndPoint from which you intend to communicate data. If you do not care which local address is assigned, you can create an IPEndPoint using IPAddress..::..Any as the address parameter, and the underlying service provider will assign the most appropriate network address. This might help simplify your application if you have multiple network interfaces. If you do not care which local port is used, you can create an IPEndPoint using 0 for the port number. In this case, the service provider will assign an available port number between 1024 and 5000.

If you use the above approach, you can discover what local network address and port number has been assigned by calling the LocalEndPoint. If you are using a connection-oriented protocol, LocalEndPoint will not return the locally assigned network address until after you have made a call to the Connect method. If you are using a connectionless protocol, you will not have access to this information until you have completed a send or receive.

Note

If you intend to receive multicast datagrams, you must call the Bind method with a multicast port number.

Note

You must call the Bind method if you intend to receive connectionless datagrams using the ReceiveFrom method.

.NET Framework Security

See Also

Reference

Socket Class

System.Net.Sockets Namespace