jpk*_*jpk 0 javascript node.js socket.io sails.js
My Sails版本为0.11.2,运行端口为1337
在assets/js/dependencies/sails.io.js中,我可以看到版本为0.11.0
下面是客户端脚本.
<script src="http://localhost/project/assets/js/dependencies/sails.io.js"></script>
<script type="text/javascript">
// `io` is available as a global.
// `io.socket` will connect automatically, but at this point in the DOM, it is not ready yet
// (think of $(document).ready() from jQuery)
//
// Fortunately, this library provides an abstraction to avoid this issue.
// Requests you make before `io` is ready will be queued and replayed automatically when the socket connects.
// To disable this behavior or configure other things, you can set properties on `io.sails`.
// You have one cycle of the event loop to set `io.sails.autoConnect` to false before the auto-connection
// behavior starts.
io.socket.get('/hello', function serverResponded (body, JWR) {
// JWR ==> "JSON WebSocket Response"
console.log('Sails responded with: ', body);
console.log('with headers: ', JWR.headers);
console.log('and with status code: ', JWR.statusCode);
// first argument `body` === `JWR.body`
// (just for convenience, and to maintain familiar usage, a la `JQuery.get()`)
});
Run Code Online (Sandbox Code Playgroud)
我收到的错误就像
Socket is trying to reconnect to Sails...
Run Code Online (Sandbox Code Playgroud)
当我检查一些其他帖子时,有说与sails版本相关的东西.我试图将sails.io.js版本更改为0.11.2,但仍然是同样的错误.
此错误与端口有任何关联吗?因为来自以下请求的响应是404
http://localhost/socket.io/?__sails_io_sdk_version=0.11.2&__sails_io_sdk_platform=browser&__sails_io_sdk_language=javascript&EIO=3&transport=polling&t=1444654910110-52
Run Code Online (Sandbox Code Playgroud)
响应
<p>The requested URL /socket.io/ was not found on this server.</p>
<address>Apache/2.2.22 (Ubuntu) Server at localhost Port 80</address>
Run Code Online (Sandbox Code Playgroud)
有什么帮助有什么不对?
您正在端口1337上运行Sails应用程序,但是sails.io.js从端口80 加载文件(因为您没有指定其他端口):
<script src="http://localhost/project/assets/js/dependencies/sails.io.js">
Run Code Online (Sandbox Code Playgroud)
我猜你有一个在端口80上运行的Apache服务器,所以它找到了sails.io.js文件并返回它,但是套接字客户端也认为它应该在端口80上连接.
使用script端口更新标记:
<script src="http://localhost:1337/js/dependencies/sails.io.js">
Run Code Online (Sandbox Code Playgroud)
或者在以下代码之前使用以下代码指定要连接的套接字的备用URL io.socket.get:
io.sails.url = "http://localhost:1337";
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1551 次 |
| 最近记录: |