C# Socket通讯 本机多网卡,指定网卡通讯
时间:2016-08-02 11:16:32
收藏:0
阅读:882
IPAddress ip = IPAddress.Parse("192.168.0.188"); IPAddress IPLocal = IPAddress.Parse("192.168.0.110"); Socket clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); try { clientSocket.Bind(new IPEndPoint(IPLocal, 0)); //绑定本地通讯使用的网卡IP clientSocket.Connect(new IPEndPoint(ip, 502)); } catch { clientSocket.Shutdown(SocketShutdown.Both); clientSocket.Close(); return; }
评论(0)