Socket io get是未定义的

我正在使用Sails的JS和我试图使用套接字IO图书馆。

正如Sails JS文档中所解释的: http ://sailsjs.org/#!documentation/ sockets

我用这个代码创build一个控制器:

index: function(req, res) { var param = req.param('msg'); console.log("PARAM : ", param); // For display the message in terminal // Send a JSON response return res.json({ success: true, message: param }); }, 

并在我的模板(我使用swig JS模板引擎):

对于包含socket io库:

 <script type="text/javascript" src="/socket.io/socket.io.js"></script> 

在JavaScript代码中:

 var socket = io.connect('http://localhost:1337'); socket.get('/echo', { message: 'hi there!' }, function(response) { console.log ('response : ', response); }); 

我有这个错误:undefined不是一个函数socket.get('/回声'…

谢谢你的帮助 !

我相信你还需要添加<script type="text/javascript" src="/app/sails.io.js"></script> 。 由于在这个文件中定义了Socket.prototype.get