惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Forbes - Security
Forbes - Security
GbyAI
GbyAI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
S
SegmentFault 最新的问题
Y
Y Combinator Blog
Recorded Future
Recorded Future
博客园 - Franky
I
InfoQ
T
The Blog of Author Tim Ferriss
Recent Announcements
Recent Announcements
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园_首页
阮一峰的网络日志
阮一峰的网络日志
T
Tailwind CSS Blog
Cyberwarzone
Cyberwarzone
The Register - Security
The Register - Security
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
雷峰网
雷峰网
P
Palo Alto Networks Blog
G
GRAHAM CLULEY
Cloudbric
Cloudbric
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
MongoDB | Blog
MongoDB | Blog
F
Full Disclosure
Google DeepMind News
Google DeepMind News
Recent Commits to openclaw:main
Recent Commits to openclaw:main
C
Check Point Blog
爱范儿
爱范儿
The GitHub Blog
The GitHub Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
W
WeLiveSecurity
T
Threat Research - Cisco Blogs
U
Unit 42
N
Netflix TechBlog - Medium
The Cloudflare Blog
Spread Privacy
Spread Privacy
Microsoft Azure Blog
Microsoft Azure Blog
美团技术团队
T
Troy Hunt's Blog
Engineering at Meta
Engineering at Meta
H
Heimdal Security Blog
TaoSecurity Blog
TaoSecurity Blog
C
Cybersecurity and Infrastructure Security Agency CISA
T
Tenable Blog
B
Blog
S
Securelist
H
Hacker News: Front Page
Google Online Security Blog
Google Online Security Blog
G
Google Developers Blog

博客园 - 白桦的天空

python+uwsgi警告 树莓派设置为竖屏显示 树莓派无桌面系统(RaspberryPI Lite)启动自动打开Chromium-Browser的具体方法 antui-alipay风格的移动网页设计 移动网页字体大小随着页面自动切换 如何使用 opencv-python 提取视频每一帧的图片? 自定义树莓派开机启动画面-plymouth版本 树莓派py文件自动运行 树莓派VLC获取实时视频流 一个标准的pygame例子 pygame镜像输出 python中使用pylet实现异屏输出 选择金额充值的选中css样式 Debian 无桌面+QT运行环境 手机外部浏览器跳转支付宝内置浏览器例子 前端动态获取后台处理进度显示在进度条上 Ventoy 多合一启动盘制作工具神器 - 将多个系统 Win/PE/Linux 镜像装在1个U盘里 pygame和pywebview配合做界面 python监听麦克风并通过websocket输出音频数据峰值目的是绘制音频曲线
通过websocket接口获取数据实时更新数据表
白桦的天空 · 2023-03-02 · via 博客园 - 白桦的天空

websocket客户端

<html>

<head>
    <title>websocket客户端</title>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
</head>

<body>
    <div>
        <canvas id="myChart"></canvas>
    </div>
    <script>
    $(document).ready(function() {

        var arrayObj = new Array();
        arrayObj.push(12);
        arrayObj.push(19);
        arrayObj.push(3);
        arrayObj.push(5);
        arrayObj.push(2);
        arrayObj.push(3);

        var ctx = document.getElementById('myChart');
        var chart = new Chart(ctx, {
            type: 'bar',
            data: {
                labels: ['Red', 'Blue', 'Yellow', 'Green', 'Purple', 'Orange'],
                datasets: [{
                    label: '# of Votes',
                    data: arrayObj,
                    borderWidth: 1
                }]
            },
            options: {
                scales: {
                    y: {
                        beginAtZero: true
                    }
                }
            }
        });





        // 创建websocket客户端
        var socket = new WebSocket("ws://127.0.0.1:8765");
        // 打开websocket
        socket.onopen = function(e) {
            socket.send("CMD");
        };
        // 接收服务器数据
        socket.onmessage = function(event) {
            console.log(event.data);
            arrayObj[0] = arrayObj[1];
            arrayObj[1] = arrayObj[2];
            arrayObj[2] = arrayObj[3];
            arrayObj[3] = arrayObj[4];
            arrayObj[4] = arrayObj[5];
            arrayObj[5] = event.data;
            chart.data.datasets[0].data = arrayObj;
            chart.update();
        };
        // 关闭websocket
        socket.onclose = function(event) {
            console.log('socket关闭');
        };
        // 错误处理
        socket.onerror = function(error) {
            console.log(error.message);
        };
        setInterval(function(){
        	socket.send("CMD");
        },1000);
    });
    </script>
</body>

</html>