区块链(8):p2p去中心化之websoket服务端实现业务逻辑

news/2024/7/11 2:12:57 标签: 区块链, p2p, 去中心化

1 业务逻辑

例如 peer1和peer2之间相互通信

peer1通过onopen{ write(Mesage(QUERY_LATEST))} 向peer2发送消息“我要最新的区块”。

peer2通过onMessage收到消息,通过handleMessage方法对消息进行处理。

handleMessage根据消息类型进行处理

RESPONSE_BLOCKCHAIN:返回区块链,RESPONSE_BLOCKCHAIN处理进入handleBlockChainResponse(receivedLatestBlock),返回的最新区块和我本地最新


http://www.niftyadmin.cn/n/5061982.html

相关文章

【小沐学前端】Node.js实现基于Protobuf协议的WebSocket通信

文章目录 1、简介1.1 Node1.2 WebSocket1.3 Protobuf 2、安装2.1 Node2.2 WebSocket2.2.1 nodejs-websocket2.2.2 ws 2.3 Protobuf 3、代码测试3.1 例子1:websocket(html)3.1.1 客户端:yxy_wsclient1.html3.1.2 客户端&#xff1a…

【Python】返回指定时间对应的时间戳

使用模块datetime,附赠一个没啥用的“时间推算”功能(获取n天后对应的时间 代码: import datetimedef GetTimestamp(year,month,day,hour,minute,second,*,relativeNone,timezoneNone):#返回指定时间戳。指定relative时进行时间推算"""根…

条件查询和数据查询

一、后端 1.controller层 package com.like.controller;import com.like.common.CommonDto; import com.like.entity.User; import com.like.service.UserService; import jakarta.annotation.Resource; import org.springframework.web.bind.annotation.GetMapping; import …

com.alibaba.csp.sentinel.slots.block.flow.FlowException: null--记录一次报错

阿丹: 记录一次开发中遇到的错误。 报错信息描述: 2023-10-01 09:47:57.263 ERROR 39572 --- [nio-9100-exec-2] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exce…

Redis与分布式-分布式锁

接上文 Redis与分布式-集群搭建 1.分布式锁 为了解决上述问题,可以利用分布式锁来实现。 重新复制一份redis,配置文件都是刚下载时候的不用更改,然后启动redis服务和redis客户。 redis存在这样的命令:和set命令差不多&#xff0…

微服务moleculer03

1. Moleculer 目前支持SQLite,MySQL,MariaDB,PostgreSQL,MSSQL等数据库,这里以mysql为例 2. package.json 增加mysql依赖 "mysql2": "^2.3.3", "sequelize": "^6.21.3", &q…

嵌入式Linux应用开发-基础知识-第十八章系统对中断的处理①

嵌入式Linux应用开发-基础知识-第十八章系统对中断的处理 第十八章 Linux 系统对中断的处理①18.1 进程、线程、中断的核心:栈18.1.1 ARM 处理器程序运行的过程18.1.2 程序被中断时,怎么保存现场18.1.3 进程、线程的概念 18.2 Linux系统对中断处理的演进…

Spring的注解开发-注解原理解析-xml方式/注解方式组件扫描

目录 Spring注解的解析原理 xml配置组件扫描 注解方式配置组件扫描 原理图 yysy,没有搞太明白,真的复杂,欢迎大佬留言解惑 Spring注解的解析原理 使用Component等注解配置完毕后,要配置组件扫描才能使注解生效 xml配置组件扫…