连接到远程机器 [英] Connect to a remote machine

查看:104
本文介绍了连接到远程机器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!
我正在开发一个项目,其中我用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);


这篇关于连接到远程机器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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