问题描述
我想在基于sailjs的项目中创建一个聊天应用程序,如何以及在哪里配置服务器中的套接字和相关设置?我从该存储库中获得了一个示例项目,但是它使用的是Sails v0.10,我需要使用Sails v0.11.3,但是在Nodejs脚本中使用套接字时,v0.11.3会有很多更改,例如,我们不能使用 onConnect ,因为它已被弃用.
I would like to create a chat application in my sailjs based project, How and where can i configure the socket and related setting in the server ? I got a sample project from this repository but it is using sails v0.10 and i need to use sails v0.11.3, but v0.11.3 having many changes while using socket in Nodejs script, for example, We can't use onConnect since it is deprecated.
我已经尝试过此示例,但是不能使用Sail v0.11.3进行此操作 https://github.com/sgress454/sailsChat
I have tried this example, but not working this with sail v0.11.3https://github.com/sgress454/sailsChat
这是我完成的代码,但是我不知道该放在哪里,当我将其放在config目录中的sockets.js文件中时,它将无法正常工作
This is the code i have done, but i don't know where should i put , it is not working when i put this in sockets.js file with in the config directory
// Set some options:
// (you have to specify the host and port of the Sails backend when using this library from Node.js)
io.sails.url = 'http://localhost:9002';
// ...
io.socket.on('connect', function socketConnected() {
console.log('connect..');
});
// Send a GET request to `http://localhost:1337/hello`:
io.socket.get('/hello', function serverResponded (body, JWR) {
// body === JWR.body
console.log('Sails responded with: ', body);
console.log('with headers: ', JWR.headers);
console.log('and with status code: ', JWR.statusCode);
// When you are finished with `io.socket`, or any other sockets you connect manually,
// you should make sure and disconnect them, e.g.:
io.socket.disconnect();
// (note that there is no callback argument to the `.disconnect` method)
});
请对此进行指导.
推荐答案
在此链接中使用主存储库后,问题已解决
Issue has been solved after using the main repository in this link
https://github.com/balderdashy/sailsChat
这篇关于如何在节点服务器中使用sails.io.js版本0.11.3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!