控制哪些网卡的TCP / IP消息是在发送 [英] Controlling which Network Card TCP/IP message are sent on

查看:150
本文介绍了控制哪些网卡的TCP / IP消息是在发送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在该系统由运行XP连接到一套嵌入式系统的.Net 2控制器电脑。所有这些组件相互通过以太网网络进行通信。我目前正在使用XP的计算机上TcpClient.Connect开到嵌入式系统的连接来发送TCP / IP信息。



我现在已经到XP的计算机连接到外部网络发送的处理数据,所以现在有两个网卡XP的计算机上。然而,发送至外部网络中的消息不能出现在网络上连接的嵌入式系统一起(不希望消耗带宽)和消息发送到嵌入式系统不能出现在外部网络上。

所以,我正在做的断言发送到定义的IP地址的消息是使用TcpClient.Connect方法时,两个网卡发送出去。



我如何指定物理网卡信息通过发送,最好使用.net网络API。如果没有这样的方法在.net存在,那么我可以随时P /调用Win32 API的。



Skizz


解决方案

请尝试使用您的客户端,而不是TcpClient的类的插座。



然后你可以用Socket.Bind瞄准本地网络适​​配器

  INT端口= 1234; 

IPHostEntry条目= Dns.GetHostEntry(Dns.GetHostName());为您的适配器这里
ip地址将localAddress = entry.AddressList.FirstOrDefault

//找到IP地址();

IPEndPoint localEndPoint =新IPEndPoint(将localAddress,口);

//使用socket,而不是一个TcpClient的
客户端的Socket =新的Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);

//绑定客户端本地端点
client.Bind(localEndPoint);

http://msdn.microsoft.com/en-us/library/system.net.sockets.socket.bind.aspx


The system I'm currently working on consists of a controller PC running XP with .Net 2 connected to a set of embedded systems. All these components communicate with each other over an ethernet network. I'm currently using TcpClient.Connect on the XP computer to open a connection to the embedded systems to send TCP/IP messages.

I now have to connect the XP computer to an external network to send processing data to, so there are now two network cards on the XP computer. However, the messages sent to the external network mustn't appear on the network connecting the embedded systems together (don't want to consume the bandwidth) and the messages to the embedded systems mustn't appear on the external network.

So, the assertion I'm making is that messages sent to a defined IP address are sent out on both network cards when using the TcpClient.Connect method.

How do I specify which physical network card messages are sent via, ideally using the .Net networking API. If no such method exists in .Net, then I can always P/Invoke the Win32 API.

Skizz

解决方案

Try using a Socket for your client instead of the TcpClient Class.

Then you can use Socket.Bind to target your local network adapter

    int port = 1234;

    IPHostEntry entry = Dns.GetHostEntry(Dns.GetHostName());

    //find ip address for your adapter here
    IPAddress localAddress = entry.AddressList.FirstOrDefault();

    IPEndPoint localEndPoint = new IPEndPoint(localAddress, port);

    //use socket instead of a TcpClient
    Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

    //binds client to the local end point
    client.Bind(localEndPoint);

http://msdn.microsoft.com/en-us/library/system.net.sockets.socket.bind.aspx

这篇关于控制哪些网卡的TCP / IP消息是在发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆