设置套接字的本地端点 [英] Setting a socket's local endpoint
问题描述
我需要创建它连接到服务器处理的插座,但必须限制使用指定的本地适配器。默认行为是使用一切所能,但我需要确保一个给定的插座仅尝试(例如),局域网连接,如果WiFi和LAN是可用的。
I need to create a socket which connects to a server process, but must be restricted to using a specified local adapter. The default behaviour is to use whatever it can, but I need to make sure that a given socket only tries (for example), the LAN connection, if both wifi and LAN are available.
我使用C#和.NET 2.0。
I am using C# and .NET 2.0.
干杯
推荐答案
的 Socket.Bind(端点localEP)
方法是你的朋友。这里在MSDN看看为详细信息。
The Socket.Bind(EndPoint localEP)
method is your friend. Look here at MSDN for the details.
要获得所有本地适配器及其类型看的 System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()
To get all local adapters and their type look at System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()
这篇关于设置套接字的本地端点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!