- 浏览: 1495469 次
- 性别:
- 来自: 北京
-
文章分类
- 全部博客 (691)
- linux (207)
- shell (33)
- java (42)
- 其他 (22)
- javascript (33)
- cloud (16)
- python (33)
- c (48)
- sql (12)
- 工具 (6)
- 缓存 (16)
- ubuntu (7)
- perl (3)
- lua (2)
- 超级有用 (2)
- 服务器 (2)
- mac (22)
- nginx (34)
- php (2)
- 内核 (2)
- gdb (13)
- ICTCLAS (2)
- mac android (0)
- unix (1)
- android (1)
- vim (1)
- epoll (1)
- ios (21)
- mysql (3)
- systemtap (1)
- 算法 (2)
- 汇编 (2)
- arm (3)
- 我的数据结构 (8)
- websocket (12)
- hadoop (5)
- thrift (2)
- hbase (1)
- graphviz (1)
- redis (1)
- raspberry (2)
- qemu (31)
- opencv (4)
- socket (1)
- opengl (1)
- ibeacons (1)
- emacs (6)
- openstack (24)
- docker (1)
- webrtc (11)
- angularjs (2)
- neutron (23)
- jslinux (18)
- 网络 (13)
- tap (9)
- tensorflow (8)
- nlu (4)
- asm.js (5)
- sip (3)
- xl2tp (5)
- conda (1)
- emscripten (6)
- ffmpeg (10)
- srt (1)
- wasm (5)
- bert (3)
- kaldi (4)
- 知识图谱 (1)
最新评论
-
wahahachuang8:
我喜欢代码简洁易读,服务稳定的推送服务,前段时间研究了一下go ...
websocket的helloworld -
q114687576:
http://www.blue-zero.com/WebSoc ...
websocket的helloworld -
zhaoyanzimm:
感谢您的分享,给我提供了很大的帮助,在使用过程中发现了一个问题 ...
nginx的helloworld模块的helloworld -
haoningabc:
leebyte 写道太NB了,期待早日用上Killinux!么 ...
qemu+emacs+gdb调试内核 -
leebyte:
太NB了,期待早日用上Killinux!
qemu+emacs+gdb调试内核
python2.7.8可用,python2.6一样的代码就有问题
https://github.com/tavendo/AutobahnPython/
git clone https://github.com/tavendo/AutobahnPython.git
为了不污染python的系统环境
假设我的当前目录是
/data/mysocket/python/
在windows中安装:
先安装virtualenv
http://wangxiaoxu.iteye.com/blog/1896624
从
https://pypi.python.org/pypi/virtualenv#downloads
下载
virtualenv-1.11.6.tar.gz
然后打开
AutobahnPython/examples/twisted/websocket/echo/client.html
F12 查看helloworld吧
twisted入门
http://outofmemory.cn/code-snippet/4624/python-twisted-example#6762184-tsina-1-61743-3400cac556b7c64aaad138f696c2c997
广播的例子修改如下
客户端html
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
广播的例子修改如下
(mysite)[root@broadcast broadcast]# 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)[root@broadcast broadcast]#
客户端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>
发表评论
-
websocket直播
2020-05-22 17:59 5671.websocket转发的最简单server 2.h5接收w ... -
openresty聊天室的helloworld
2018-04-22 19:25 878openresty的websocket + redis的sub ... -
openresty websocket
2018-04-18 17:08 1598mac安装openresty brew install o ... -
nginx代理wss和https
2018-02-27 15:34 3974nginx启用ssl yum install openssl ... -
websocket和tap使用select关联
2016-06-14 22:01 772c语言的socket基础http://haoningabc.i ... -
websocket传传图片
2015-12-25 17:51 7267参考[url]http://www.adobe.com/dev ... -
websocket相关调研 总结帖
2014-12-21 21:53 4090最近把websocket的客户端和服务端使用过的调通的例子总结 ... -
scrapy的helloworld
2014-12-01 16:02 897http://scrapy.org/ 安装python vi ... -
tornado和telegraphy的helloworld
2014-11-11 14:09 903参考 http://www.tornadoweb.cn/ t ... -
ios websocket server端
2014-10-22 00:07 2222https://github.com/benlodotcom/ ... -
ios客户端websocket的helloworld
2014-10-09 02:11 23234ios8,xcode6 https://github.com/ ... -
websocket,使用tomcat7转发
2014-10-03 18:40 11778前篇: http://haoningabc.iteye.com ... -
python2.7 vlrtualenv
2014-09-20 22:57 1010如果是2.6用这个,最好用2.7, virtualenv ht ... -
redis验证
2014-02-27 16:32 1855去randomkey #!/usr/bin/python2 ... -
websocket的helloworld
2014-02-06 23:47 14206ChatClient.java ChatServer.java ... -
python的udp的socket
2011-12-07 00:11 1277apple:udp apple$ cat UDPClient. ... -
python发邮件
2011-11-18 16:12 1000代码要最简化 import datetime impor ... -
转 让Django支持数据库长连接
2011-11-16 00:18 1035http://www.cnblogs.com/Alexande ... -
解决“No module named django.core”
2011-09-07 18:22 6350反复的删除django和重装就会有这个问题 bogon:~ ... -
找到python的site-packages文件夹在哪
2011-09-06 17:55 5151python -c "from distutils. ...
相关推荐
mConnection.sendTextMessage("Hello, world!"); } @Override public void onTextMessage(String payload) { Log.d(TAG, "Got echo: " + payload); } @Override public void onClose(int code, String ...
【计算机求职笔试】资源
# 基于Apache Spark Mllib的Bronze机器学习平台 ## 项目简介 Bronze是一个构建在Apache Spark Mllib之上的机器学习平台,旨在提供全面的数据接入、转换、训练、测试和输出功能。该平台支持多种机器学习算法模型,并提供丰富的插件来处理数据预处理、特征工程、模型训练和验证等任务。 ## 项目的主要特性和功能 ### 数据处理流程 1. 数据采集从各种数据源(如Fake、File、HDFS)接入数据。 2. 数据预处理对数据进行清洗、转换和格式化。 3. 特征工程生成和选择特征,包括特征提取、转换和选择。 4. 模型训练使用多种分类和回归模型进行训练。 5. 模型验证对训练好的模型进行验证和评估。 6. 模型持久化将训练好的模型保存到持久化存储中。 7. 模型结果输出输出模型的最终结果。 ### 支持的算法模型 #### 分类模型 逻辑回归支持大规模特征和无限训练样例,输出类别数小于1000万。
Java项目基于Springboot框架的课程设计,包含LW+ppt
资源内项目源码是均来自个人的课程设计、毕业设计或者具体项目,代码都测试ok,都是运行成功后才上传资源,答辩评审绝对信服的,拿来就能用。放心下载使用!源码、数据集、部署说明一站式服务,拿来就能用的绝对好资源!!! 项目备注 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 2、本项目适合计算机相关专业(如计科、人工智能、通信工程、自动化、电子信息等)的在校学生、老师或者企业员工下载学习,也适合小白学习进阶,当然也可作为毕设项目、课程设计、大作业、项目初期立项演示等。 3、如果基础还行,也可在此代码基础上进行修改,以实现其他功能,也可用于毕设、课设、作业等。 下载后请首先打开README.dataset.txt文件,仅供学习参考, 切勿用于商业用途。 4、如有侵权请私信博主,感谢支持
内容概要:本文详细探讨了全球定位系统(GPS)的信号产生、捕获和追踪三个核心步骤,并通过Matlab源码实现相关算法。首先介绍了GPS信号产生的关键要素,包括伪随机码生成、数据编码和信号发射。接着讨论了信号捕获过程,涉及天线接收、码相位测量及其常用方法如滑动相关法。最后阐述了信号追踪的三边测量原理及误差修正措施,如电离层延迟补偿、地形效应补偿和多路径效应修正。通过具体Matlab代码示例展示了整个流程的实现,并附带了详细的运行步骤和结果分析。 适合人群:对GPS系统有兴趣的研究人员和技术爱好者,尤其是有一定编程基础并希望深入了解GPS内部机制的人群。 使用场景及目标:适用于学术研究、工程开发等领域,旨在帮助读者掌握GPS信号处理的基本理论和实践技能,提升定位精度和可靠性。 其他说明:文中提供的Matlab代码已在特定版本下测试通过,但不同版本可能存在差异。此外,还列举了一些参考文献供进一步学习。
基于Andorid条形二维码识别设计实现源码,主要针对计算机相关专业的正在做毕设的学生和需要项目实战练习的学习者,也可作为课程设计、期末大作业。
NRF24L01收发例程
AcWing算法基础课Notion笔记html页面
[Excel在财务管理中的应用(第六版)(微课版)]配书资源
# 基于多线程的Web客户端程序 ## 项目简介 本项目是一个基于多线程的Web客户端程序,旨在并发地从Web服务器获取多个文件。通过使用多线程技术,程序能够高效地处理多个文件请求,提高整体性能。 ## 项目的主要特性和功能 多线程并发请求支持同时从多个Web服务器获取文件,提高请求效率。 TCP连接管理每个线程负责建立TCP连接并发送HTTP GET请求。 线程同步与通信使用互斥锁和条件变量确保线程间的同步和数据一致性。 命令行参数解析支持解析命令行参数,获取连接的最大数量和要获取的文件列表。 文件处理每个线程负责读取服务器的响应并处理文件内容。 ## 安装使用步骤 1. 下载源码假设用户已经下载了本项目的源码文件。 2. 编译项目使用合适的编译器(如GCC)编译项目源码。 bash gcc o webclient main.c lpthread
中学学生“诚信”教育班会课件
1、文件说明: Centos8操作系统tacacs-devel-F4.0.4.28.7fb~20231005g4fdf178-2.el8.rpm以及相关依赖,全打包为一个tar.gz压缩包 2、安装指令: #Step1、解压 tar -zxvf tacacs-devel-F4.0.4.28.7fb~20231005g4fdf178-2.el8.tar.gz #Step2、进入解压后的目录,执行安装 sudo rpm -ivh *.rpm
内容概要:本文详细介绍了如何利用LabVIEW通过网口与西门子PLC进行高效通讯的方法和技术细节。首先解释了西门子S7Comm协议的三层结构(TPKT+COTP+S7),并通过具体实例展示了如何构造和发送十六进制命令帧。接着提供了完整的LabVIEW代码片段,涵盖从TCP连接建立、命令帧发送、响应接收及数据解析的全过程。文中还分享了多种实用技巧,如批量读写、强制写入、自动重连机制等,并对比了原生TCP与OPC UA的性能差异。最后,通过实际案例验证了该方案在工业应用中的优越性和稳定性。 适合人群:从事工业自动化领域的工程师和技术人员,尤其是熟悉LabVIEW和西门子PLC的用户。 使用场景及目标:适用于需要与西门子PLC进行高效、稳定的网口通讯的应用场景,旨在提高通讯效率、降低系统复杂度和成本。 其他说明:文中提供的代码和技巧可以帮助开发者更好地理解和掌握LabVIEW与西门子PLC之间的通讯机制,从而应用于各种工业控制系统中。
matlab
内容概要:本文详细介绍了基于CH579芯片的以太网转串口服务器的实现过程。首先,文章讲解了硬件配置,包括使用的芯片及其特性,如CH579M、PHY芯片HR911105A和电平转换电路SGM48017。接着,重点剖析了网络初始化代码,强调了PHY复位时序、MAC地址传递和硬件协议栈处理ARP和ICMP协议的重要性。随后,文章深入探讨了串口数据处理,展示了环形缓冲区的实现和中断服务函数的优化。此外,还介绍了协议转换的状态机实现,以及内存池分配的精妙之处。最后,文章总结了资源管理策略,如DMA自动搬运数据、中断嵌套机制和零拷贝技术,使得服务器能够实现稳定的3Mbps转发速率。 适合人群:具有一定嵌入式开发经验的研发人员,尤其是对以太网转串口服务器感兴趣的工程师。 使用场景及目标:适用于需要深入了解嵌入式系统中以太网转串口服务器的工作原理和技术实现的人群。目标是掌握CH579芯片的硬件配置、网络初始化、串口数据处理、协议转换和资源管理等方面的知识。 其他说明:文中提供了详细的代码示例和硬件设计要点,帮助读者更好地理解和应用相关技术。建议读者结合实际项目进行实践,逐步掌握核心技术。
Java项目基于Springboot框架的课程设计,包含LW+ppt
Java项目基于Springboot框架的课程设计,包含LW+ppt
2025清华大学:迈向未来的AI教学实验-393页.pdf
亲子教育“正面管教”教案课件