我想在基于水手的项目中创建一个聊天应用程序,如何在服务器上配置套接字和相关设置?我从这个存储库中获得了一个示例项目,但它使用的是sails v0.10,我需要使用sails v0.11.3,但是v0.11.3在Nodejs脚本中使用套接字时有很多更改,例如,我们不能使用onConnect,因为它是不推荐使用的。
我试过这个例子,但没有使用SEALV0.11.3 https://github.com/sgress454/sailsChat
这是我已经完成的代码,但是我不知道我应该把它放在哪里,当我把它放在sockets.js文件中时,它不能工作。
// 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)
});请给我带路。
发布于 2016-05-10 14:14:21
在此链接中使用主存储库后,问题已得到解决。
https://stackoverflow.com/questions/37129766
复制相似问题