首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用Node.js制作一个可移植的在线聊天应用程序是否可行?

用Node.js制作一个可移植的在线聊天应用程序是否可行?
EN

Stack Overflow用户
提问于 2011-09-19 19:55:30
回答 2查看 274关注 0票数 1

我想知道是否可以使用Node.js开发一个便携式聊天应用程序。

我的意思是,如果有一个提供Node.js聊天服务的中央网站,用户可以获取脚本代码(不管是基于JavaScript还是iframe),并将聊天程序发布到他们的网站上。

假设此应用程序托管在chatServer.com

例如,如果用户有一个div,其ID为适当的表单输入,并且已将chatServer.com中的一个脚本链接起来。

  1. 用户只需查看聊天页面即可。(例: chatServer.com/chat/room/roomName)

)

  1. 使用flash swf将其移植到页面.

如果我没记错的话,JSON数据不能跨不同的域进行交易。

你认为这是可能的申请吗?

我只想知道是否有可能建造它。

我见过一些类似的web聊天应用程序,它们是用'Python twisted'+'swf‘实现的。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-09-19 21:13:01

如果您使用socket.io,它将简单地使用jsonp进行跨域通信。

代码语言:javascript
复制
<script src="//chatServer.com/socket.io.js"></script>
<script>
  var socket = io.connect('//chatServer.com');
  socket.on('chat', function (data) {
    console.log(data);
    socket.emit('my other event', { my: 'data' });
  });
</script>
票数 2
EN

Stack Overflow用户

发布于 2016-04-12 07:39:41

我面临跨域问题,我的app.js代码是

代码语言:javascript
复制
 var express = require('express'),
 app = express();
 var port = process.env.PORT || 8080;

// Initialize a new socket.io object. It is bound to 
// the express app, which allows them to coexist.

var io = require('socket.io').listen(app.listen(port));

// Require the configuration and the routes files, and pass
// the app and io as arguments to the returned functions.
  io.use(function(socket, next) {
   var handshakeData = socket.request;
    //console.log(handshakeData);
    next();

                });

    // Require the configuration and the routes files, and pass
     // the app and io as arguments to the returned functions.

   app.use(function(req, res, next) {
      res.header("Access-Control-Allow-Origin", "*");
      res.header("Access-Control-Allow-Headers", "X-Requested-With");
      res.header("Access-Control-Allow-Methods", "GET,POST");
      next();
     });
    require('./config')(app, io);
    require('./routes')(app, io);

    console.log('Your application is running on http://localhost:' + port);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7476542

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档