使用IP地址连接到另一台计算机 [英] Connect to another computer using IP address

查看:327
本文介绍了使用IP地址连接到另一台计算机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的计算机上安装了NodeJS并运行了一些测试,所有这些都可以在我的机器上正常工作。现在我想要一个不在同一网络中的朋友连接到我的计算机,以便NodeJS可以响应我朋友的请求。但我不知道,我必须听哪个IP和端口,我不知道,我必须给我的朋友哪个IP,他可以连接到我的电脑。

I installed NodeJS on my computer and ran some tests and all works fine on my machine. Now I want a friend, that is not in the same network, to connect to my computer, so that NodeJS can response to my friend's request. But I don't know, on which IP and port I have to listen to and I don't know, which IP I have to give my friend, that he can connect to my computer.

我已经尝试通过命令提示符和 ipconfig 获取我的公共计算机IP,但所有连接到此地址的尝试都失败了。此外,当我的朋友连接到我的路由器的IP地址。

I already tried to get my public computer IP via command prompt and ipconfig, but all attempts to connect to this address failed. Also when my friend connects to my router's IP address.

我做错了什么以及如何正确地做到这一点?

What am I making wrong and how to do it correctly?

推荐答案

您需要:


  • 打开计算机和路由器上的端口(例如3000),设置
    你的路由器将开放端口路由到你的计算机。

  • 运行
    脚本来监听计算机ip
    计算机的所有网络接口(0.0.0.0)。

  • 然后您的朋友将能够通过开放端口连接您的路由器IP

  • Open a port on your computer and router (for example 3000), setting up your router to route the open port to your computer.
  • Run your script to listen your computer ip or all network interfaces of the computer (0.0.0.0).
  • Then your friend will be able to connect on your router ip through the open port.

精确配置取决于您的计算机/路由器。

尝试使用此基本节点服务器脚本:

The precise configuration depend a lot of your computer/router.
To try you can use this basic node server script:

var http = require('http');

http.createServer(function(req, res){
    res.writeHead(200, {'content-type': 'text/plain'});
    res.end('It works');
}).listen(3000, '0.0.0.0');

这篇关于使用IP地址连接到另一台计算机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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