通过客户端服务器连接到远程计算机 [英] Connecting to a remote machine through client-server

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

问题描述

我在vb.net中创建了一个简单的tcp客户端-服务器应用程序.当我将本地主机(127.0.0.1)设置为IP地址时,一切正常.我希望与远程计算机建立连接(将客户端保留在我的计算机上,将服务器保留在另一台计算机上,反之亦然).

如果我有其外部IP地址,该如何连接到远程计算机?我曾尝试在互联网上进行搜索,但无法澄清这一点.非常感谢!



好的,感兴趣的代码如下:

服务器:


昏暗的服务器作为TcpListener = New TcpListener(IPAddress.Any,port)

客户端:

将IP调暗为IPAddress = IPAddress.Parse(TextBox1.Text)
客户端=新的TcpClient(theip.ToString,port)

现在,如果我的客户端位于远程计算机(通过Internet连接)上并且服务器位于另一台计算机(其外部IP地址已知)上,那么我应该在"TextBox1.Text"中输入什么?
我可以在文本框中直接输入运行服务器的计算机的外部IP地址吗?另外,我是否需要处理端口转发"/让防火墙允许连接"之类的事情?

I have created a simple tcp client-server application in vb.net. Everything works fine when i set local host (127.0.0.1) as the ip address. I wish to make a connection to a remote machine (keeping client at my machine and server on the other - or vice versa).

How can i connect to the remote machine if i have its external ip address? I have tried searching on the internet but couldn''t clarify this. Thanks a lot!



ok, the code of interest is as follows:

the server:


Dim server As TcpListener = New TcpListener(IPAddress.Any, port)

the client:

Dim theip As IPAddress = IPAddress.Parse(TextBox1.Text)
client = New TcpClient(theip.ToString, port)

Now, what should i enter in "TextBox1.Text" if i have my client on a remote machine (connected over internet) and server at a different computer (whose external IP address is known)?
Can i enter the external IP address of the machine running the server directly in the text box? Also, do i need to take care of things like "port forwarding" / "let firewall allow the connection" and all?

推荐答案

请参阅:

socket-bind-返回的请求的地址在无线上下文中无效 [ ^ ]
tcpclient-exception-requested-address-not- valid-its-context-t [
See:

socket-bind-returns-the-requested-address-is-not-valid-in-its-context-on-wi[^]
tcpclient-exception-requested-address-not-valid-its-context-t[^]

[This error usually results from an attempt to bind a listening socket to an IP address that''s not valid for the local machine.]

Of course you have to allow the connection via the firewall (in case it is set to block such a connection), other wise the firewall will be pretty much useless.

Cheers,
Edo


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

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