假设我有以下代码:
def foo(s):
"""A dummy function foo. For example:
>>> a = '''This is a test string line 1
This is a test string line 2
This is a test string line 3'''
>>> foo(a)
This is a test string line 1
This is a test string line 2
This is a test string line 3
>>>
"""
print s
if __name__ == '__main__':
import doctest
doctest.testmod()
Run Code Online (Sandbox Code Playgroud)
让我们把它保存为foo.py. 当我跑:
C:\Python27>python.exe foo.py
**********************************************************************
File "foo.py", line 5, in __main__.foo
Failed example: …Run Code Online (Sandbox Code Playgroud) 我知道这个问题有点尴尬,但问题来自三星电视2010/2011年SmartTV(和蓝光播放器;当然2012年模拟器工作正常).我将简单的聊天示例从源和包移植到SmartTV应用程序.它们都回归到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);
});
});
Run Code Online (Sandbox Code Playgroud)
的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 …Run Code Online (Sandbox Code Playgroud)