简体   繁体   English

如何将本地服务器转换为在线服务器 Node.js

[英]How to convert local server to online server Node.js

I've been developing this game for a school project.我一直在为学校项目开发这款游戏。 It is supposed to be online multiplayer, but this far i have online used it locally.它应该是在线多人游戏,但到目前为止我已经在本地在线使用它。 I can figure out how to change my server code for it to be able to act as a "real" online server.我可以弄清楚如何更改我的服务器代码以使其能够充当“真正的”在线服务器。

The server code:服务器代码:

// Dependencies
var express = require('express');
var http = require('http');
var path = require('path');
var socketIO = require('socket.io');

var app = express();
var server = http.Server(app);

app.set('port', 5000);
app.use('/static', express.static(__dirname + '/static'));

// Routing
app.get('/', function(request, response)
{
  response.sendFile(path.join(__dirname, 'index.html'));
});



// Starts the server.
server.listen(5000, function()
{
  console.log('Starting server on port 5000');
});


// Add the WebSocket handlers
io.on('connection', function(socket)
{
  console.log('New player arrived');
}); 

Would appreciate any help greatly.非常感谢任何帮助。

Most of the shared servers run at port 8080大多数共享服务器运行在8080 端口

so you may change the port then upload it into the hosting, If you just need it to be live u can use https://heroku.com/ so u can deploy it there所以你可以更改端口然后将其上传到主机中,如果你只需要它是活的,你可以使用https://heroku.com/所以你可以在那里部署它

also here's quick option还有这里的快速选项

npm install -g localtunnel
lt --port 8000

You will receive a URL, for example, https://school.localtunnel.me , that you can share with anyone for as long as your local instance of lt remains active.您将收到 URL,例如https://school.localtunnel.me ,只要您的本地 lt 实例保持活动状态,您就可以与任何人共享该文件。 Any requests will be routed to your local service at the specified port任何请求都将被路由到指定端口的本地服务

For more info: https://localtunnel.github.io/www/欲了解更多信息: https://localtunnel.github.io/www/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM