maven
<dependency>
<groupId>org.java-websocket</groupId>
<artifactId>Java-WebSocket</artifactId>
<version>1.3.5</version>
</dependency>
代码
@Slf4j
@Component
public class WESWebSocketClient extends WebSocketClient {
@Autowired
private WebSocketProcessor webSocketProcessorFor;
private static WebSocketProcessor webSocketProcessor;
@PostConstruct
public void init() {
webSocketProcessor = webSocketProcessorFor;
}
public WESWebSocketClient() throws URISyntaxException {
super(new URI("ws://127.0.0.1:9102/ws"));
}
public WESWebSocketClient(String url) throws URISyntaxException {
super(new URI(url));
}
@Override
public void onOpen(ServerHandshake shake) {
log.info("握手...");
}
@Override
public void onMessage(String paramString) {
PbStationExtendInfo pbStationExtendInfo = JSONUtil.toBean(paramString, PbStationExtendInfo.class);
log.info("接收到消息:"+paramString);
webSocketProcessor.processor(pbStationExtendInfo);
}
@Override
public void onMessage(ByteBuffer bytes) {
log.info("ByteBuffer 接收到消息:"+bytes);
super.onMessage(bytes);
}
@Override
public void onClose(int paramInt, String paramString, boolean paramBoolean) {
log.info("关闭...paramInt:"+paramInt+" paramString:"+paramString+" paramBoolean:"+paramBoolean);
}
@Override
public void one rror(Exception e) {
log.info("异常"+e);
}
public void sendMsg(String msg) throws InterruptedException {
this.send(msg);
}
}
标签:info,websocket,log,service,void,Override,层去,public,paramString From: https://www.cnblogs.com/daleyzou/p/17995381/useWebsocket