1 整个流程梳理
- 服务开启onStart()
- 连接打开onOpen()
- 处理接收到的消息onMesage()
- 连接关闭onClose()
- 异常处理onError()
2 创建p2p实现类
package com.example.demo.service;
import com.example.demo.entity.BlockChain;
import org.java_websocket.WebSocket;
import org.java_websocket.handshake.ClientHandshake;
import org.java_websocket.server.WebSocketServer;
import java.net.InetSocketAddress;
import java.util.ArrayList;
public class P2PService {
private BlockChain blockService;
public P2PService(BlockChain blockService) {
this.blockService = blockService;
this.sockets = new ArrayList<