use*_*195 5 sockets chat node.js
我从这个页面学到了一点 - > https://github.com/Automattic/socket.io/issues/1846
我需要SSL才能使套接字工作吗?

我一直在努力解决这个错误很长一段时间没有解决方案到目前为止,是否有任何天才可以解决这个难题?
我的应用代码
var express = require("express");
var app = express();
var http = require('http').Server(app);
var io = require('socket.io')(http);
app.use(express.static(__dirname + '/html'));
http.listen(process.env.PORT || 3000, function(){
console.log('listening on *:', process.env.PORT || 3000);
new shell.Shell(app, io);
});
app.use(function(request, response, next){
response.header("Access-Control-Allow-Origin", "*");
response.header("Access-Control-Allow-Methods", "GET,PUT,POST,DELETE,OPTIONS");
response.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, X-Auth-Token");
request.id = self.id++;
next();
});
var self = this;
app.get("/", function(request, response) {
response.end("");
});
app.get("/entitlement/:uri", function(request, response){
self.delegate.entitlement(request, response);
});
app.get("/speakers", function(request, response) {
self.delegate.speaker(request, response);
});
app.get("/speakers/:id", function(request, response) {
self.delegate.speaker(request, response);
});
app.get("/sponsors", function(request, response){
self.delegate.sponsor(request, response);
});
app.get("/sponsors/:id", function(request, response) {
self.delegate.sponsor(request, response);
});
app.get("/agendas", function(request, response) {
self.delegate.agenda(request, response);
});
app.get("/agendas/:id", function(request, response) {
self.delegate.agenda(request, response);
});
app.get("/sessions/:id", function(request, response){
self.delegate.agenda(request, response);
});
app.get("/attendees", function(request, response) {
//self.delegate.attendee(request, response);
});
///attendees/:id to get chat history
io.on("connection", function(socket){
//self.delegate.connection(io, socket, null);
socket.on('get-age-in-dog-years', function(data, fn) {
console.log(data);
fn(data.age * 7) ;
});
socket.on("chat", function(chat){
//self.delegate.chat(io, socket, chat);
});
socket.on("disconnect", function(){
//self.delegate.disconnect(io, socket)
});
});
},
Run Code Online (Sandbox Code Playgroud)
您可能将 socket.io 连接到服务器端的错误项目。使用express 时,您的http 对象是不必要的。可以直接附加到express应用程序吗?看这里:
http://socket.io/docs/#using-with-the-express-framework
var io = require('socket.io')(app)
Run Code Online (Sandbox Code Playgroud)
这可能会为您的应用程序附加提供错误的参考。
| 归档时间: |
|
| 查看次数: |
3980 次 |
| 最近记录: |