Javascript 使用c9.io设置节点js服务器
我很难在c9.io上设置一个节点服务器来运行一个简单的应用程序。首先,服务器在localhost上运行没有问题,但原因是c9呈现html,但不使用socket.io。。这是我的代码: App.jsJavascript 使用c9.io设置节点js服务器,javascript,c9.io,Javascript,C9.io,我很难在c9.io上设置一个节点服务器来运行一个简单的应用程序。首先,服务器在localhost上运行没有问题,但原因是c9呈现html,但不使用socket.io。。这是我的代码: App.js const http = require('http'); const socketio = require('socket.io'); const express = require('express'); const app = express(); const server = http.cr
const http = require('http');
const socketio = require('socket.io');
const express = require('express');
const app = express();
const server = http.createServer(app);
const io = socketio.listen(server);
app.get('/', (req, res) => res.sendFile(`${__dirname}/client/index.html`))
io.on('connection', socket => {
socket.on('move', data => {
io.emit('move', data)
})
})
server.listen(process.env.PORT || 3000, process.env.IP || "0.0.0.0", () => {
const addr = server.address();
console.log("Chat server listening at", `${addr.address}:${addr.port}`);
});
index.html
<!doctype html>
<html lang="en" ng-app>
<head>
<title>Chat Example</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="/css/bootstrap.min.css">
<link rel="stylesheet" href="/css/bootstrap-responsive.min.css">
<style>
body {
padding-top: 60px;
}
</style>
<script>
const socket = io.connect('https://socket-alexcnu.c9users.io/'); /* global io $*/
$(document).on('mousemove', e => {
let data = {x: e.pageX - 10 , y: e.pageY - 10}
$('div').css({
left: e.pageX - 10,
top: e.pageY - 10
});
socket.emit('move', data)
});
socket.on('move', data => {
console.log(data.x);
$('div').css({
left: data.x,
top: data.y
});
})
</script>
</head>
<body>
<div style = 'height: 20px; width: 20px; background: orange; position:absolute; float:left'></div>
</body>
<script src="/socket.io/socket.io.js"></script>
<script src="/js/jquery.min.js"></script>
</html>
谷歌浏览器控制台
https://socket-alexcnu.c9users.io/css/bootstrap-responsive.min.css Failed to load resource: the server responded with a status of 404 (Not Found)
https://socket-alexcnu.c9users.io/css/bootstrap.min.css Failed to load resource: the server responded with a status of 404 (Not Found)
socket-alexcnu.c9users.io/:14 Uncaught ReferenceError: io is not defined
2https://socket-alexcnu.c9users.io/js/jquery.min.js Failed to load resource: the server responded with a status of 404 (Not Found)
https://socket-alexcnu.c9users.io/css/bootstrap-responsive.min.css Failed to load resource: the server responded with a status of 404 (Not Found)
https://socket-alexcnu.c9users.io/css/bootstrap.min.css Failed to load resource: the server responded with a status of 404 (Not Found)
以下是我的作品:
聊天示例
身体{
填充顶部:60px;
}
常量套接字=io.connect('https://socket-alexcnu.c9users.io/'); /* 全球io$*/
$(文档).on('mousemove',e=>{
设data={x:e.pageX-10,y:e.pageY-10}
$('div').css({
左:e.pageX-10,
排名:e.pageY-10
});
socket.emit('move',data)
});
socket.on('move',data=>{
console.log(data.x);
$('div').css({
左:data.x,
顶部:data.y
});
})
以下内容对我很有用:
聊天示例
身体{
填充顶部:60px;
}
常量套接字=io.connect('https://socket-alexcnu.c9users.io/'); /* 全球io$*/
$(文档).on('mousemove',e=>{
设data={x:e.pageX-10,y:e.pageY-10}
$('div').css({
左:e.pageX-10,
排名:e.pageY-10
});
socket.emit('move',data)
});
socket.on('move',data=>{
console.log(data.x);
$('div').css({
左:data.x,
顶部:data.y
});
})
将
放在第一个脚本块之前。@Nehal J Wani仍然是相同的调试…将
放在第一个脚本块之前。@Nehal J Wani仍然是相同的调试。。。
https://socket-alexcnu.c9users.io/css/bootstrap-responsive.min.css Failed to load resource: the server responded with a status of 404 (Not Found)
https://socket-alexcnu.c9users.io/css/bootstrap.min.css Failed to load resource: the server responded with a status of 404 (Not Found)
socket-alexcnu.c9users.io/:14 Uncaught ReferenceError: io is not defined
2https://socket-alexcnu.c9users.io/js/jquery.min.js Failed to load resource: the server responded with a status of 404 (Not Found)
https://socket-alexcnu.c9users.io/css/bootstrap-responsive.min.css Failed to load resource: the server responded with a status of 404 (Not Found)
https://socket-alexcnu.c9users.io/css/bootstrap.min.css Failed to load resource: the server responded with a status of 404 (Not Found)