Bind a socket (including UdpClient and TcpClient) to a local network interface card (NIC)


/ Published in: C#
Save to your folder(s)

If you are using a UdpClient or TcpClient, you have access to the internal Socket which either type uses. Unfortunately, if you try to Bind that Socket to a local Endpoint (IPAddress and Port), you will probably get a SocketException. The solution I found is to create the Socket independently, then assign that instance to the UdpClient (as shown in the code) or TcpClient (changing the Socket parameters, of course).

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.