且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用IP地址连接到另一台计算机

更新时间:2022-12-23 22:24:47

您需要:


  • 打开计算机和路由器上的端口(例如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');