我正在尝试在localhost上连接一个wamp服务器,这是一个html页面。
到目前为止,我有这个:
//SOCKET.IO Setup
var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http); //initialise after http server
io.on('connection', function(socket){
console.log('a user connected');
socket.on('disconnect', function(){
console.log('user disconnected');
});
});
http.listen('/wheel', function(){
console.log('listening on */wheel');
});
app.get('/', function(req, res){
res.sendfile('wheel.html');
});
我在www / wheel中有HTML页面,html页面叫做wheel.html
这是我得到的错误:
[17:08:51] error - Error: listen EACCES
at exports._errnoException (util.js:746:11)
at Server._listen2 (net.js:1139:19)
at listen (net.js:1182:10)
at Server.listen (net.js:1261:5)
at Object.<anonymous> (C:\Family\wheel.js:14:6)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:501:10)
如何使用socket.io正确连接到localhost中的web目录?它在我使用套接字和端口时起作用:
http.listen(1000, function(){
console.log('listening on *:1000');
});
app.get('/', function(req, res){
res.sendfile('wheel.html');
});
答案 0 :(得分:1)
问题在于您是否尝试让HTTP服务器在名为/
的{{3}}上收听,而您没有正确的权限来创建该文件。< / p>
如果您希望能够在客户端在服务器上调用http.listen(3000);
...
app.get('/', function(req, res){
res.sendfile('./www/wheel/wheel.html');
});
(例如,正在侦听端口3000)时提供HTML文件:
CREATE TABLE dog
(
DogID int(6) NOT NULL,
DogName varchar(15),
medicalID int (6),
Gender character(1) check(gender in ('m', 'f')),
Age int(2),
Breed varchar(15),
size character (1) check(size in ('s', 'm', 'l')),
primary key (DogID));
CREATE TABLE Owns
(
DogID int (6)primary key,
CustomerID int (6),
foreign key (CustomerID) references customer (CustomerID),
foreign key (DogID) references dog (DogID));
CREATE TABLE customer
(
CustomerID int(6) NOT NULL,
FirstName varchar(15),
Surname varchar(15),
Address varchar(225),
email varchar (30),
TelNo varchar (15),
MobNo Varchar (15),
EmergencyName varchar (40),
EmergencyPhoneNo varchar(15),
primary key (CustomerID));