我知道这个问题有点棘手,但问题来自三星2010/2011智能电视(和蓝光播放器;当然2012模拟器运行良好)。我将源码和包中的简单聊天示例移植到智能电视应用程序中。它们都回退到JSONP轮询,但仅从SmartTV应用程序中可以向服务器发出/推送一次。从服务器接收消息可能会多次而没有任何问题。在三星D论坛上寻找答案后(当然没有任何信息),我认为解决这个问题最快的方法是部署一个Express服务器,接收POST数据并执行JSON.parse,然后在服务器内部发布Socket.io/Sockjs。
“我的其他事件”似乎没有接收到任何东西。
有人能给我展示一个简单的代码样本,让我从那里开始吗?非常感谢。
我很快编写了代码,但似乎它无法工作:
lib/server.js
var express = require('express')
, app = express.createServer()
, io = require('socket.io').listen(app);
app.listen(80);
app.use(express.bodyParser());
app.get('/', function (req, res) {
res.sendfile('/var/www/mpgs_lite_v3/index.html');
});
app.post('/', function(req, res){
console.log(req.body);
io.sockets.emit('my other event', req.body);
res.redirect('back');
});
io.sockets.on('connection', function (socket) {
//socket.emit('news', { hello: 'world' });
socket.on('my other event', function (data) {
console.log(data);
});
});
index.html
<html>
<head>
<script src="/socket.io/socket.io.js"></script>
<script>
var socket = io.connect('http://localhost');
socket.on('news', function (data) {
console.log(data);
socket.emit('my other event', { my: 'data' });
});
</script>
</head>
<body>
<form method="post" action="/">
<input type="hidden" name="_method" value="put" />
<input type="text" name="user[name]" />
<input type="text" name="user[email]" />
<input type="submit" value="Submit" />
</form>
</body>
</html>
“我的其他事件”似乎没有接收到任何东西。