当前位置: 首页 > news >正文

阿里云主机安装wordpress/淘宝seo搜索排名优化

阿里云主机安装wordpress,淘宝seo搜索排名优化,装修公司前十强有哪些,博客网站建设方案最近在网上找了些websocket的资料看了下,node和tornado等等本身已经实现了websocket的封装,所以使用起来会比较简单,php如果想要写websocket还需要自己跑一整套流程,比较麻烦。 根据网上的资料写了一个简单的websocket的demo&…

最近在网上找了些websocket的资料看了下,node和tornado等等本身已经实现了websocket的封装,所以使用起来会比较简单,php如果想要写websocket还需要自己跑一整套流程,比较麻烦。

根据网上的资料写了一个简单的websocket的demo,果真炫酷掉渣天,我是用tornado,网上多是实现实时聊天室的例子,想要实现点对点的聊天功能还需要在send函数那里加条件,目测是根据浏览器用户的id去判断的。代码如下:

服务端代码:

#!/usr/bin/python
#coding:utf-8
import os.pathimport tornado.httpserver
import tornado.web
import tornado.ioloop
import tornado.options
import tornado.httpclient
import tornado.websocketimport json
class IndexHandler(tornado.web.RequestHandler):def get(self):self.render("index.html")class SocketHandler(tornado.websocket.WebSocketHandler):"""docstring for SocketHandler"""clients = set()@staticmethoddef send_to_all(message):for c in SocketHandler.clients:c.write_message(json.dumps(message))def open(self):self.write_message(json.dumps({'type': 'sys','message': 'Welcome to WebSocket',}))SocketHandler.send_to_all({'type': 'sys','message': str(id(self)) + ' has joined',})SocketHandler.clients.add(self)def on_close(self):SocketHandler.clients.remove(self)SocketHandler.send_to_all({'type': 'sys','message': str(id(self)) + ' has left',})def on_message(self, message):SocketHandler.send_to_all({'type': 'user','id': id(self),'message': message,})##MAIN
if __name__ == '__main__':app = tornado.web.Application(handlers=[(r"/", IndexHandler),(r"/chat", SocketHandler)],debug = True,template_path = os.path.join(os.path.dirname(__file__), "templates"),static_path = os.path.join(os.path.dirname(__file__), "static"))app.listen(8000)tornado.ioloop.IOLoop.instance().start()

客户端代码:

<html>
<head>
<script type="text/javascript">
var ws = new WebSocket("ws://localhost:8000/chat");
ws.onmessage = function(event) {console.log(event);
}
function send() {ws.send(document.getElementById('chat').value );
}
</script>
</head><body><div>hello<input id="chat"><button  οnclick="send()">send</button></div>	
</body>
</html>


http://www.jmfq.cn/news/5065795.html

相关文章:

  • 做蛋糕招聘网站/常州网站建设
  • 成全视频免费观看在线看中国片/seo全称是什么意思
  • 许昌市建设局网站/网络营销策划书封面
  • 老河口市网站/百度首页百度一下
  • 传奇私服的网站是怎么做的/南宁seo服务优化
  • 小本本教你做网站/优秀的营销案例
  • 辛集哪做网站/厦门网站建设
  • 艾艺公司团队定制/seo推广思路
  • wordpress食品模板/佛山seo培训
  • 墨鱼网站建设/关键词分为哪三类
  • php动态网站建设 总结/培训网站模板
  • wordpress的cute主题破解版/深圳seo推广
  • 网站首页的图标是怎么做的/企业网站排名优化
  • 唯品会一个专做特卖的网站广告/建网站教学
  • 免费搭建个人网站的3种实用方法/外国搜索引擎登录入口
  • 在线甜点订购网站开发需求分析/浏览广告赚钱的平台
  • 域名解析映射到网站空间怎么做/百度关键词排名突然消失了
  • 汕头哪里做网站/hao123影视
  • 自己创建一个app要多少钱/合肥seo优化排名公司
  • 天津低价做网站/河南seo网站多少钱
  • 邢台制作网站/最近七天的新闻大事
  • 阿里云国外服务器/东莞seo管理
  • 如何做微信网站建设/2020年可用好用的搜索引擎
  • 网站设计就业怎么样/成都seo网站qq
  • 用以前用过的域名做网站/海豹直播nba
  • wordpress 标签 rss/seo排名工具哪个好
  • 网站格式有哪些内容/营销策划方案ppt范文
  • 靖江网站制作多少钱/指数是什么
  • 阿里云做的网站怎么备份/百家号seo
  • 电子商务公司网站怎么建/百度数据研究中心