积极答复者
关于设置Socket.ExclusiveAddressUse 属性

问题
-
答案
全部回复
-
可以参考 MSDN, 需要使用 Socket.Bind 方法。
http://msdn.microsoft.com/en-us/library/system.net.sockets.socket.exclusiveaddressuse.aspx
If ExclusiveAddressUse is false, multiple sockets can use the Bind method to bind to a specific port; however only one of the sockets can perform operations on the network traffic sent to the port. If more than one socket attempts to use the Bind(EndPoint) method to bind to a particular port, then the one with the more specific IP address will handle the network traffic sent to that port.
或者http://msdn.microsoft.com/zh-cn/library/system.net.sockets.socket.exclusiveaddressuse.aspx
ExclusiveAddressUse 为 false,则多个套接字可以使用 Bind 方法绑定到特定端口;不过,只有其中的一个套接字可以对发送到该端口的网络流量执行操作。 Bind(EndPoint) 方法绑定到特定端口,则将由具有最为具体的 IP 地址的套接字来处理发送到该端口的网络流量。
学习学习....
-
你好,
不要用 new IPEndPoint
而是将它定义成一个公共变量
IPEndPoint ipend = new IPEndPoint(Dns.GetHostAddresses(Dns.GetHostName())[0], 8888); public void Myfunccc() { Socket s1 = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); s1.ExclusiveAddressUse = false; s1.Bind(ipend); }
有问题,请继续跟贴。谢谢。
Mike Feng
MSDN Community Support | Feedback to us
Please remember to mark the replies as answers if they help and unmark them if they provide no help.