因为很少有这样作为客户端的使用,但是遇上特殊需求还是要作为客户端使用,spring-boot-starter集成的无法实现客户端,直接上代码
pom引入,这里使用的spring boot 其他项目自行下载jar包库
org.java-websocket
Java-WebSocket
1.3.8
package com.jwuwb.library.service.websocket;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.jwuwb.library.entity.PositionStation;
import com.jwuwb.library.service.PositionStationService;
import org.java_websocket.WebSocket.READYSTATE;
import org.java_websocket.client.WebSocketClient;
import org.java_websocket.handshake.ServerHandshake;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.net.URI;