public Bind ( |
||
localEP | ||
return | void |
using System.Net; using System.Net.Sockets; // Create a new socket Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); // Create an endpoint IPEndPoint endpoint = new IPEndPoint(IPAddress.Parse("192.168.1.100"), 8080); // Bind the socket to the endpoint socket.Bind(endpoint);
using System.Net; using System.Net.Sockets; // Create a new socket Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); // Create an endpoint with an IPAddress of "any" (0.0.0.0) and port 8080 IPEndPoint endpoint = new IPEndPoint(IPAddress.Any, 8080); // Bind the socket to the endpoint socket.Bind(endpoint);In this example, we create an endpoint object with an IP address of "any" (0.0.0.0), which means the socket will bind to any available IP address on the system. This can be useful if you want to listen for incoming connections on all network interfaces. We again use the `Bind` method to associate the socket with this endpoint. Both of these examples use classes from the `System.Net` and `System.Net.Sockets` namespaces, which are provided by the .NET Framework.