Communicate between computers through Ethernet cable

倖福魔咒の 提交于 2019-12-13 23:58:21

问题


I want to connect two computers with an Ethernet cable without the user having to set up a LAN through the Control Panel and then transfer data between two instances of my app - one running on each computer.

As soon as I have a connection with an IP address for each computer, I know I can easily transfer a file by using Sockets, Pipes(?), WCF... But both computers are also connected via wifi to a router, so how can I somehow tell the computer that for a specific IP address - please use the cable? (I might be getting all of this wrong. Please feel free to correct me.)

I can use a UWP app or a .net (Winform/WPF) app. Either technology is fine. But this must be done in code, not by the users setting up a LAN through the Control Panel. Also, IPv6 is fine too.


回答1:


Each network card has its own IP address, so both of the computers will have IP address for the WIFI network and another IP address for the ad-hoc link. The addresses for the ad-hoc link can be set to an address in one IP segment, for example, 10.0.0.1 and 10.0.0.2, if the WIFI addresses are in the range of 192.168.X.X. Your OS will know which card is related to each IP segment.




回答2:


Start with System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces().

Filter out the Type=EtherNet interfaces and make sure they're Up. You may also have to watch out for virtual adapters etc.

From the selected adapter you can get Address Information etc. The IPV4 address should probably be enough to get you started.



来源:https://stackoverflow.com/questions/45056235/communicate-between-computers-through-ethernet-cable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!