@coco 我已经搞定了,是redis没有清除历史数据导致的, [npm install -g redis-cli,rdcli -u redisurl flushall]手动清除后问题就解决了,目前已经成功通过docker部署在阿里云的集群容器里面了,感谢您提供支持;
Posts made by renjianfeng
您好,我修改了./node_modules/@colyseus/proxy/bin/proxy的代码,新增了日志打印,希望能有所参考,具体修改如下如下:
// query pre-existing nodes
discovery_1.getNodeList().
then(function (nodes) {
return nodes.forEach(function (node) { console.log("详情3",node,nodes);return register(node); });
}).
catch(function (err) { return console.error(err); });
发现getNodeList返回的数组中有个别端口为undefined
详情3 { processId: '2NOMTd-kb', address: '172.16.225.246:7001' } [
2|proxy | { processId: '2NOMTd-kb', address: '172.16.225.246:7001' },
2|proxy | { processId: 'N9tmo8HJP', address: '172.16.225.246:undefined' },
2|proxy | { processId: 'ezYAPhlUO', address: '172.16.225.246:7000' },
2|proxy | { processId: 'C7yXZ8SvL', address: '172.16.225.246:7003' },
2|proxy | { processId: 'rPS3NmHCA', address: '172.16.225.246:7001' },
2|proxy | { processId: '7K1i4pnko', address: '172.16.225.246:7002' },
2|proxy | { processId: 'JDwRKgWKY', address: '172.16.225.246:7002' },
2|proxy | { processId: '-LI0NAxC7', address: '172.16.225.246:7002' },
2|proxy | { processId: 'Av8G4ggJB', address: '172.16.225.246:7003' },
2|proxy | { processId: 'TxwZ5Vani', address: '172.16.225.246:undefined' },
2|proxy | { processId: 'x_ZlF1Cjc', address: '172.16.225.246:7001' },
2|proxy | { processId: 'fBRAR1jCx', address: '172.16.225.246:7000' }
2|proxy | ]
这导致了代理失败,因为端口号不能为undefined,具体报错如下:
2|proxy | Using proxy 1 /matchmake/joinOrCreate/game
2|proxy | RangeError [ERR_SOCKET_BAD_PORT]: Port should be >= 0 and < 65536. Received undefined.
2|proxy | at new NodeError (node:internal/errors:372:5)
2|proxy | at validatePort (node:internal/validators:217:11)
2|proxy | at lookupAndConnect (node:net:1035:5)
2|proxy | at Socket.connect (node:net:1011:5)
2|proxy | at Agent.connect [as createConnection] (node:net:203:17)
2|proxy | at Agent.createSocket (node:_http_agent:340:26)
2|proxy | at Agent.addRequest (node:_http_agent:291:10)
2|proxy | at new ClientRequest (node:_http_client:311:16)
2|proxy | at Object.request (node:http:96:10)
我使用mac os系统在本地进行多进程测试,我不知道这是否有影响,还是我必须找一个干净的容器。nodejs版本v16.15.1,其他包版本如下:
"@colyseus/proxy": "^0.12.8",
"@colyseus/redis-driver": "^0.14.22",
"colyseus": "^0.14.0",
"pm2": "^5.2.0",
"tsc": "^2.0.4"
@COCO 您好
感谢您提供中文社区的指导,我按照您的指引 (https://github.com/colyseus/proxy) 设置了动态代理,但我发现动态代理中有3处设置端口的地方,我在前端发起请求的时候应该以哪个端口为准。我发现当我以8083发起的时候,仍然出现:
ServerError: seat reservation expired.的错误,
但如果以9001发起则请求不通:
POST http://127.0.0.1:9001/matchmake/joinOrCreate/game net::ERR_EMPTY_RESPONSE
以下是ecosystem.config.js的内容:
const os = require('os');
module.exports = {
apps: [
{
port : 8083,
name : "colyseus",
script : "lib/index.js", // your entrypoint file
watch : true, // optional
instances : os.cpus().length,
exec_mode : 'fork', // IMPORTANT: do not use cluster mode.
env: {
DEBUG: "colyseus:errors",
NODE_ENV: "production",
}
},
{
port:9001,
name : "colyseus-proxy",
script : "./node_modules/@colyseus/proxy/bin/proxy",
instances : 1, // scale this up if the proxy becomes the bottleneck
exec_mode : 'cluster',
env: {
PORT:9001,
REDIS_URL: "redis://省略...:6379/0"
}
}
]
}
hi~
Socket.io can get user IP in the following ways. How can colyseus do similar things?
io.request.connection.remoteAddress