Skip to content

xueqing/websocket-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 

Repository files navigation

websocket 学习

参考链接

windows 环境

  • 安装 python
    • 下载 python2.7
    • 安装
    • 配置系统环境变量,添加两个路径到 Path
      • absolute_path\Python27\Scripts
      • absolute_path\Python27
    • 测试:打开命令提示符,输入python,输出Python 2.7.15......
  • 安装 pywebsocket
    • 克隆源码git clone https://github.com/google/pywebsocket.git
    • 进入 pywebsocket 目录,执行命令
      • python setup.py build
      • python setup.py install
  • 开启服务python standalone.py -p 9998 -w ../example/
    • 以上命令会开启一个端口号为 9998 的服务,使用 -w 来设置处理程序 echo_wsh.py 所在的目录

websocket client

  • 可以在浏览器打开index.html,连接的 url 写ws://localhost:9998/echo
  • pywebsocket 会把收到的消息再发送给 client

websocket server

  • 编写 server 和 client 代码,使用 websocket 通信
  • 安装ws模块:npm install ws
  • 创建文件夹server/scriptsserver/pages
  • 开启服务:在命令行打开app.jsnode ./app.js

licode demo