autobahn的helloworld

python2.7.8可用,python2.6一样的代码就有问题

https://github.com/tavendo/AutobahnPython/

git clone https://github.com/tavendo/AutobahnPython.git

为了不污染python的系统环境
假设我的当前目录是
/data/mysocket/python/

virtualenv twisted
cd twisted/
source bin/activate
echo $VIRTUAL_ENV
echo $PATH
进入
python setup.py install

pip install zope.interface

yum install libffi-devel
yum install bzip2-devel

安装twisted 这里可能会报错
bz2模块找不到之类的
参考http://stackoverflow.com/questions/8115280/importerror-no-module-named-bz2-for-python-2-7-2
先 把动态库copy到2.7的
cp /usr/lib64/python2.6/lib-dynload/bz2.so /data/mysocket/python/twisted/lib/python2.7/

pip install twisted

cd AutobahnPython\examples\twisted\websocket\echo>
python server.py


在windows中安装:
先安装virtualenv
http://wangxiaoxu.iteye.com/blog/1896624
从
https://pypi.python.org/pypi/virtualenv#downloads
下载
virtualenv-1.11.6.tar.gz
python setup.py install
在python/Scripts中多了virtualenv.exe
virtualevn twist
cd twist
Scripts/activate.bat
pip install zope.interface
pip install twisted

(twist) D:\pythonwork\AutobahnPython\examples\twisted\websocket\echo>python serv
er.py
2014-11-08 20:45:22+0800 [-] Log opened.
2014-11-08 20:45:22+0800 [-] WebSocketServerFactory starting on 9000
2014-11-08 20:45:22+0800 [-] Starting factory <autobahn.twisted.websocket.WebSoc
ketServerFactory instance at 0x0000000002BBF288>


然后打开
AutobahnPython/examples/twisted/websocket/echo/client.html
F12 查看helloworld吧


twisted入门
http://outofmemory.cn/code-snippet/4624/python-twisted-example#6762184-tsina-1-61743-3400cac556b7c64aaad138f696c2c997


广播的例子修改如下
[code="java"]
(mysite)# cat server.py
###############################################################################
##
## Copyright (C) 2011-2013 Tavendo GmbH
##
## Licensed under the Apache License, Version 2.0 (the "License");
## you may not use this file except in compliance with the License.
## You may obtain a copy of the License at
##
## http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
##
###############################################################################

import sys

from twisted.internet import reactor
from twisted.python import log
from twisted.web.server import Site
from twisted.web.static import File
import time
from autobahn.twisted.websocket import WebSocketServerFactory, \
WebSocketServerProtocol, \
listenWS


class BroadcastServerProtocol(WebSocketServerProtocol):

def onOpen(self):
self.factory.register(self)
msg="open "+str(time.time())
print msg
self.sendMessage(msg.encode('utf8'))

def onMessage(self, payload, isBinary):
if not isBinary:
#msg = "{} from {}".format(payload.decode('utf8'), self.peer)
#self.factory.broadcast(msg)
self.factory.broadcast(payload)

def connectionLost(self, reason):
WebSocketServerProtocol.connectionLost(self, reason)
self.factory.unregister(self)


class BroadcastServerFactory(WebSocketServerFactory):
"""
Simple broadcast server broadcasting any message it receives to all
currently connected clients.
"""

def __init__(self, url, debug = False, debugCodePaths = False):
WebSocketServerFactory.__init__(self, url, debug = debug, debugCodePaths = debugCodePaths)
self.clients = []
#self.tickcount = 0
#self.tick()

def tick(self):
self.tickcount += 1
self.broadcast("tick %d from server" % self.tickcount)
reactor.callLater(1, self.tick)

def register(self, client):
if not client in self.clients:
print("registered client {}".format(client.peer))
self.clients.append(client)

def unregister(self, client):
if client in self.clients:
print("unregistered client {}".format(client.peer))
self.clients.remove(client)

def broadcast(self, msg):
print("broadcasting message '{}' ..".format(msg))
for c in self.clients:
c.sendMessage(msg.encode('utf8'))
print("message sent to {}".format(c.peer))


class BroadcastPreparedServerFactory(BroadcastServerFactory):
"""
Functionally same as above, but optimized broadcast using
prepareMessage and sendPreparedMessage.
"""

def broadcast(self, msg):
print("broadcasting prepared message '{}' ..".format(msg))
preparedMsg = self.prepareMessage(msg)
for c in self.clients:
c.sendPreparedMessage(preparedMsg)
print("prepared message sent to {}".format(c.peer))


if __name__ == '__main__':

if len(sys.argv) > 1 and sys.argv[1] == 'debug':
log.startLogging(sys.stdout)
debug = True
else:
debug = False

ServerFactory = BroadcastServerFactory
#ServerFactory = BroadcastPreparedServerFactory

factory = ServerFactory("ws://0.0.0.0:9000",
debug = debug,
debugCodePaths = debug)

factory.protocol = BroadcastServerProtocol
factory.setProtocolOptions(allowHixie76 = True)
listenWS(factory)

webdir = File(".")
web = Site(webdir)
reactor.listenTCP(8080, web)

reactor.run()
(mysite)#
[/code]
客户端html

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
<script type="text/javascript">
String.prototype.startWith=function(s){
if(s==null||s==""||this.length==0||s.length>this.length)
return false;
if(this.substr(0,s.length)==s)
return true;
else
return false;
return true;
}
Date.prototype.format = function(format) {
var o = {
"M+" : this.getMonth() + 1, //month
"d+" : this.getDate(), //day
"h+" : this.getHours(), //hour
"m+" : this.getMinutes(), //minute
"s+" : this.getSeconds(), //second
"q+" : Math.floor((this.getMonth() + 3) / 3), //quarter
"S" : this.getMilliseconds()
}
if (/(y+)/.test(format))
format = format.replace(RegExp.$1, (this.getFullYear() + "")
.substr(4 - RegExp.$1.length));
for ( var k in o)
if (new RegExp("(" + k + ")").test(format))
format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k]
: ("00" + o[k]).substr(("" + o[k]).length));
return format;
}
var ws = null;
function log(text) {
/* document.getElementById("log").innerHTML = (new Date).getTime() + ": "
+ text + "<br>" + document.getElementById("log").innerHTML; */
document.getElementById("log").innerHTML = new Date().format('yyyy-MM-dd hh:mm:ss') + ","
+ text + "<br>" + document.getElementById("log").innerHTML;
}
function enterSend(){
if(event.keyCode == 13){
document.getElementById("sendbtn").click();
}
}
function startServer() {

var url = document.getElementById("serverip").value;// "ws://192.168.0.102:8887";
if ('WebSocket' in window) {
ws = new WebSocket(url);
} else if ('MozWebSocket' in window) {
ws = new MozWebSocket(url);
} else {
log('浏览器不支持');
return;
}
ws.onopen = function() {
log('唷嘻,连上了');
};
// 收到服务器发送的文本消息, event.data表示文本内容
ws.onmessage = function(event) {
var thisdata = event.data;
if(thisdata.startWith("open")){
//alert(thisdata);
document.getElementById("username").value=thisdata.split(" ")[1];
}else{
//log(event.data);
var showData=event.data.split(",");
log(showData[0]+"说:"+showData[2]);
}
};
ws.onclose = function() {
log('Closed! 刷新页面尝试连接.');
}
}
function sendMessage() {
var textMessage = document.getElementById("textMessage").value;
var username = document.getElementById("username").value;
var toUser = document.getElementById("toUser").value;;
if (ws != null && textMessage != "") {
ws.send(username+","+toUser+","+textMessage);
}
document.getElementById("textMessage").value="";
}
function stopconn() {
ws.close();
}
</script>
<body onload="startServer()">

<input id="serverip" type="text" size="20"
value="ws://182.254.155.153:9000" />

</br>
您的Id:<input id="username" type="text" readonly/></br>
to Id:<input id="toUser" type="text" /> 如果为空则群发</br>
<input id="textMessage" type="text" size="20" onkeydown="enterSend()" style="border:1;width:400px" />
<input id="sendbtn" type="button" onclick="sendMessage()" value="Send">
<div id="log"></div>
</body>
</html>

CMU OpenFace 关于OpenFace的各种依赖库dependencies 的安装配置部分,可以参见之前的文章dlib, OpenFace and face_recognition。 下面纪录一下测试OpenFace本身的各种应用时遇到的问题。Demo 4: Real-Time Face Embedding VisualizationRunning Command python demos/sphere.py 阅读详情

相关推荐

autobahn-python, 在 python 中为 Twisted 和 asyncio,web socket和,.zip

autobahn-python, 在 python 中为 Twisted 和 asyncio,web socket和, Autobahn|Pythonweb socket & WAMP用于 Twisted 和asyncio上的python 。 快速链接: 源代码 - 文档- web socket示例- web WebSocke

解决 Python 项目中自定义包“No module named...” 错误

在 Python 项目中,导入模块和包是很常见的操作,但有时候你可能会遇到这样的错误信息。这种错误通常是由于 Python 无法找到所需的模块或包导致的。本文将探讨这个错误的可能原因,并提供解决方法。

weixin_44172157的博客 1万+

科研绘图避坑指南:用PyMol制作期刊级蛋白-配体相互作用图(含氢键显示技巧)

本文是一份专业的科研绘图避坑指南,详细讲解如何利用PyMol软件制作符合期刊发表标准的蛋白-配体相互作用图。文章重点分享了从构图逻辑、精准选择到氢键等相互作用的艺术化表达技巧,并提供了视觉优化与期刊适配的终极参数设置,帮助科研人员产出兼具科学严谨性与视觉美感的专业图表。

weixin_29292431的博客 270

pycharm中对于no module named xxx的解决方法

在pycharm中,当使用sys.path.append设置文件导入路径时,其下的文件在被import时,仍然会标红提示 no module named xxx.如:解决方法如下,找到目标文件所在的文件夹,标记其为source root即可

Auto Testing Blog 1万+

Apifox 自动化测试新增流程控制条件,复杂测试场景不再是问题

在 if 条件后的输入框填写请求接口得到的变量 viewed ,选择条件为「小于」,输入比较数值 10 ,并在 if 条件下添加「宠物下架处理」步骤。借助新增的自动化测试流程控制条件,测试人员就可以使用 Apifox 去实现更深层更多样的测试应用场景,帮助提升测试效率,减少复杂场景的测试操作。「查询新建宠物」、「修改宠物状态为已售出」和「查询宠物状态是否修改」步骤为当前在售宠物信息盘点的三个标准步骤,所以将这三个步骤合成一组。在循环中添加「查询在售宠物」和「修改宠物状态」步骤;

877

【ACP】2025-最新-疑难题解析-1

即用户手动释放时,因实例释放保护开启,不会释放该 ECS 实例(不同云厂商具体实现有差异,但题目场景下选 C )。结合题目中标记,答案为。综上,答案选 B。综上,答案选 C。综上,答案选 D。综上,答案选 A。综上,答案选 A。综上,答案选 C。综上,答案选 D。综上,答案选 A。

jundao1997的专栏 364

Ubuntu16.04下openface安装

安装openface的前三步都是按照这个博客的进行的  链接:http://www.linuxdiyf.com/linux/20268.html 第四步:安装torch按照官网进行     git clone https://github.com/torch/distro.git ~/torch --recursive cd ~/torch; bash install-deps; ./in

云杉的博客 6209

ResNet改进(50):SKConv和CBAM增强的ResNet模型

动态调整感受野大小- 结合通道和空间注意力模型的核心思想是在ResNet的每个残差块后插入这些注意力模块,使网络能够自适应地关注更重要的特征。模型的核心是类,它在标准ResNet34的基础上:替换了初始卷积层,使用更小的核(3×3)和步长(1)在每个残差块后选择性添加SKConv和CBAM模块# 加载预训练ResNet34# 自定义初始层# 添加注意力机制的残差层通过集成SKConv和CBAM,这个改进的ResNet模型能够更有效地捕捉多尺度特征并关注关键信息区域。

2401_82355416的博客 621

python webscoket(Autobahn)的使用

自从18年4月份入职游戏公司之后很少有时间写博客了! 今天来聊聊python的websocket的使用,在游戏行业游戏客户端和服务端需要大量的,快速的通讯,这里面就会用到websocket Autobahn 是一个高性能的websocket 它采用了两种实现方案 1 基于Twisted 2 基于asyncio Autobahn 有如下的特点: framework...

lucky404的博客 6954

青岛鼎信Java开发面试题及参考答案(3万字长文,多张原理图)

MySQL 的事务特性有哪些? MySQL 事务具有四个重要特性,被称为 ACID 特性。 原子性(Atomicity):事务是一个不可分割的工作单位,事务中的操作要么全部执行,要么全部不执行。例如,在银行转账场景中,从账户 A 转账到账户 B,包括扣减账户 A 的金额和增加账户 B 的金额这两个操作必须作为一个整体来完成。如果在执行过程中发生错误,比如系统崩溃或者数据库出现故障,那么已经执行的部分必须全部回滚,就好像整个转账操作从未发生过一样。 一致性(Consistency):事务必须

大模型大数据攻城狮的专栏 1088

Qt C++ 串口调试助手

1. **串口配置**:支持自动检测可用串口,可配置波特率(9600~921600)、数据位(5~8)、校验位(无/奇/偶/标记/空格)、停止位(1/1.5/2)。- HEX 模式发送时,输入格式需为十六进制字符(0-9、A-F),可带空格(如 `01 A3 FF`)或不带空格(如 `01A3FF`)。// 发送模式:true=HEX,false=ASCII。// 字符串转HEX字节数组。ui->parity->addItems({"无", "奇校验", "偶校验", "标记校验", "空格校验"});

寒寒豆豆软件公司的博客 147

关于PyCharm中出现ModuleNotFoundError: No module named 'PyQt5'问题的解决

原文链接:https://blog.youkuaiyun.com/qq_33485434/article/details/80606359 感谢原文博主给出的解决方法,此文只是转载。 PyCharm不识别PyQt5的问题如图所示,引用PyQt5的时候显示错误“ModuleNotFoundError: No module named ‘pyqt5’” 首先确定已经安装了PyQt5是成功的 Python\Pyth...

u014157109的博客 8544

《UDS协议从入门到精通》系列——图解0x10:诊断会话控制

什么是诊断会话控制服务?切换模式时ECU要做哪些?有没有通信示例?本文全网最详解!!

车载系统攻城狮 1万+

pycharm 报错 ModuleNotFoundError: No module named '_cffi_backend'

Here's the output ofpip freeze, for reference: [root@machine ~]# pip freeze argparse==1.2.1 autobahn==0.8.10 cffi==1.5.2 characteristic==14.3.0 pika==0.9.13 pyasn1==0.1.7 pyasn1-modules==0.0.8 pycp...

0x8g1T9E- 1万+

uniapp - 实现扫码功能自定义扫描二维码/条码界面+手电筒轻触照亮+扫码屏幕添加手动输入框,手机扫描二维码并跳转过程,调用手机原生摄像头进行扫码且自动识别执行事件(uniApp安卓苹果App端)

uniapp,app端,安卓app,苹果ios,uniapp扫码识别,二维码展示和扫码,uniapp如何实现扫码功能,uni-app实现扫码功能,二维码和一维码/条码扫描,UniApp实现扫描二维码,uniapp开发原生app页面的扫码功能,自定义扫码界面,uniapp怎么调用扫一扫功能,app自定义扫码界面,uniapp 自定义扫一扫页面,扫码手电筒功能,自定义扫描框,扫码报错怎么办,扫码黑屏,扫一扫摄像头黑屏,uniapp扫码原生插件,最新扫码组件,连续扫码,uniapp APP扫码,扫码后如何处理跳转

✅ 精选推荐文章 1万+

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

websocket autobahn webrtc

最近分析webrtc android 的交互流程(房间服务器、信令、穿透等),发现webrtc是使用的是autohahn 的 websocket,初步看了下发现这个库封装的很不错,就分享出来,下面的 内容是来自网上。。 Autobahn Android是一个开源的网络类库用于Java/Android应用。实现了 The WebSocket Protocol 和The WebS

webrtc 1725

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

autobahn-python的使用——sendMessage()和断线自动重连

客户端代码:# -*-coding:utf8-*- import threading import timefrom autobahn.asyncio.websocket import WebSocketClientProtocolfrom autobahn.asyncio.websocket import WebSocketClientFactory import asyncioclass Bas

benhuo931115的博客 4664

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

Pycharm中引用本地文件py失败,显示红色波浪线,运行时提示ModuleNotFoundError: No module named 'XXXX'解决办法

在pycharm项目中,我自己定义了一些函数放在algorithm_integration.py文件,在同一文件夹下的另一views.py文件中使用from algorithm_integration import *时显示下划红色波浪线,在运行的时候提示ModuleNotFoundError。 上面是我的项目目录树和显示波浪线问题,网上查了资料后,应该进行如下操作: 1.在Setting...

Nin7a的博客 1982

报错:ModuleNotFoundError: No module named ‘cv_bridge‘,以及在ROS是如何安装cv_bridge库包

#1 问题原因分析 在个错误是由于安装的ros版本并没有带cv_bridge库包,所以在导入的时候报错:ModuleNotFoundError: No module named 'cv_bridge' >>> from cv_bridge import CvBridge Traceback (most recent call last): File "<stdin>", line 1, in <module> ModuleNotFoundError: No mo

求真、务实 1万+

找到python的site-packages文件夹在哪

python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()" echo $PYTHONPATH 转卸载django方法:http://apps.hi.baidu.com/share/detail/16026679 [code="java"]删除任何旧版本的Django 如果你打算...

走在左边 6990

解决“No module named django.core”

反复的删除django和重装就会有这个问题 [code="java"]bogon:~ apple$ django-admin.py startproject aa Traceback (most recent call last): File "/usr/local/bin/django-admin.py", line 2, in from django.core imp...

走在左边 1354

Textmate调试Python

转http://phaibin.72pines.com/2011/08/11/textmate%E8%B0%83%E8%AF%95python/ [code="java"]Textmate调试Python 要让Textmate调试Python的时候在光标停在编辑器里面,类似XCode的效果,需要安装PdbTextMateSupport。方法是: sudo easy_install P...

走在左边 561

python调用tt

把附件图片的jpg改成pdf,为tt的电子书 --------------------------- pytyrant apt-get install python-setuptools apt-get install python-pytyrant apt-get install python-memcache 下面这个好使 svn checkout http://pyty...

走在左边 543

vim python

现在见了空行就想dd 参考http://www.linux-wiki.cn/index.php/%E9%85%8D%E7%BD%AE%E5%9F%BA%E4%BA%8EVim%E7%9A%84Python%E7%BC%96%E7%A8%8B%E7%8E%AF%E5%A2%83 http://www.vim.org/scripts/script.php?script_id=790 ...

走在左边 385

scrapy的helloworld

http://scrapy.org/ 安装python virlualenv yum install libxslt-devel yum install python-devel libffi-devel cp /usr/lib64/python2.6/lib-dynload/bz2.so Scrapy/lib/python2.7/ 否则可能汇报bz2的错误 pip insta...

走在左边 302
上一篇: shader and Program编程基本概念 - 转
下一篇: chrome app的helloworld
linux内核控
博客等级 码龄19年 41粉丝 638原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值