开发者

Node + Connect + WebSockets

开发者 https://www.devze.com 2023-01-29 16:41 出处:网络
I am looking for a WebSockets lib/middleware for connect The one I found so far开发者_如何学Go is Socket.IO-connect however it uses patched version of Connect.

I am looking for a WebSockets lib/middleware for connect

The one I found so far开发者_如何学Go is Socket.IO-connect however it uses patched version of Connect.

This is an issue mainly due to the separation of patched version of Connect from the main branch.

Can you recommend a good library?


Right now, it's a bad time for WebSockets, Mozilla and Opera won't ship them with the upcoming versions due to some problems with the protocol and broken proxies, which allow for cache poisoning. It very likely that Google will also drop support until the protocol has been fixed.

So as of now, it doesn't make much sense to search for a middleware as the protocol will change very soon and then you'll have to search yet again, so for now you can just as well use the patched version if you really need to.

For details see:
http://hacks.mozilla.org/2010/12/websockets-disabled-in-firefox-4/
http://blog.pusherapp.com/2010/12/9/it-s-not-websockets-it-s-your-broken-proxy


You do not need a connect middleware for socket.io, and infact it's probably not the best way to go about using socket.io with connect. Here is what I do:

var connect = require('connect');
var io = require('socket.io');

var server = connect.createServer(
  connect.router(function(app) {
    app.get('/', function(req, res, next) {
      res.writeHead(200, {'Content-Type': 'text/html'});
      res.end(fs.readFileSync(__dirname + '/assets/index.html', 'utf8'));
      // above file contains <script src="/socket.io/socket.io.js" type="text/javascript"></script>
    });
  })
).listen(80);

var socket = io.listen(server);
socket.on('connection', function(client) {
  client.on('message', function(message) {console.log(message)});
  client.on('disconnect', function() {});
});


My version of socket.io-connect should work well.

0

精彩评论

暂无评论...
验证码 换一张
取 消