连接到远程机器

编程入门 行业动态 更新时间:2024-10-24 10:21:12
本文介绍了连接到远程机器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

嗨! 我正在开发一个项目,其中我用tcplistener类和tcpclient类连接两台计算机,但是tcpclient需要一个ip,因为它变化很大,我想使用tcpserver类使用名称来访问计算机计算机或任何其他方法,这可能吗?我想不用电线就可以连接它们,没有必要使用这些类,我只是指出了这样做的方式. 接受任何建议=) 谢谢

Hi ! I''m developing a project in which i connect two computers with a tcplistener class and a tcpclient class, but the tcpclient requires an ip , since it changes a lot , i would like to access the computer with the tcpserver class using the name of the computer or any other method, is this possible? I want to connect them without any wire and it is not necessary to use those classes, i just point the way I''m doing it. any recommendation is accepted =) Thanks

推荐答案

您还可以通过运行TcpListener的远程计算机的DNS名称构造TpcClient.请参见构造函数System.Net.Sockets.TcpClient(string hostname, int port).一台计算机可以有一个以上的IP,并且其中只有一个与给定的DNS条目相关联,因此这是唯一可靠的关联.
—SA
You can also construct TpcClient by DNS name of the remote computer running TcpListener. See the constructor System.Net.Sockets.TcpClient(string hostname, int port). A computer can have more then one IP, and only one of them is associated with a given DNS entry, so this is the only reliable association.
—SA

如果您知道PC名称,则: If you know the PC name, then: using System.Net; ... string strHostName = "MYPCNAME"; IPHostEntry ipEntry = Dns.GetHostByName (strHostName); IPAddress [] addr = ipEntry.AddressList; IPAddress ip = addr[0]; Console.WriteLine("{0}", ip);

更多推荐

连接到远程机器

本文发布于:2023-11-23 21:04:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1622856.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:连接到   机器

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!