消息推送错误结束字符串

dev
anthonywj 2 years ago
parent 60887e6f46
commit 20d0da6075

@ -1,5 +1,6 @@
package com.glxp.sale.admin.socket.client; package com.glxp.sale.admin.socket.client;
import cn.hutool.core.thread.ThreadUtil;
import com.glxp.sale.admin.constant.SocketMsgType; import com.glxp.sale.admin.constant.SocketMsgType;
import com.glxp.sale.admin.service.param.SystemParamConfigService; import com.glxp.sale.admin.service.param.SystemParamConfigService;
import com.glxp.sale.admin.thread.HeartTaskService; import com.glxp.sale.admin.thread.HeartTaskService;
@ -29,34 +30,40 @@ public class WebSocketComponent implements CommandLineRunner {
@Override @Override
public void run(String... args) throws Exception { public void run(String... args) throws Exception {
String ip = systemParamConfigService.selectValueByParamKey("upper_server_ip");
ip = ip.replace("http://", ""); ThreadUtil.execAsync(() -> {
try { String ip = systemParamConfigService.selectValueByParamKey("upper_server_ip");
SpsWebSocketClient client = new SpsWebSocketClient("ws://" + ip + "/spms/sync/1/" + socketToken); ip = ip.replace("http://", "");
client.setSocketMsgService(socketMsgService); try {
initConnect(client); SpsWebSocketClient client = new SpsWebSocketClient("ws://" + ip + "/spms/sync/1/" + socketToken);
//等待WebSocket服务端响应 client.setSocketMsgService(socketMsgService);
String message = null;
while (true) {
while ((message = client.getExcptMessage()) == null) {
log.info("已连接,等待接收数据--------");
Thread.sleep(1000);
if (client.isClosed()) {
initConnect(client); initConnect(client);
//等待WebSocket服务端响应
String message = null;
while (true) {
while ((message = client.getExcptMessage()) == null) {
log.info("已连接,等待接收数据--------");
Thread.sleep(1000);
if (client.isClosed()) {
initConnect(client);
}
}
if (message.contains(SocketMsgType.DL_ALL_DATA)) {
heartTaskService.dlAllData();
}
//打印服务端返回的数据
log.info("成功获取数据:" + message);
}
} catch (URISyntaxException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
} }
} }
if (message.contains(SocketMsgType.DL_ALL_DATA)) { );
heartTaskService.dlAllData();
}
//打印服务端返回的数据
log.info("成功获取数据:" + message);
}
} catch (URISyntaxException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
} }
public void initConnect(SpsWebSocketClient client) { public void initConnect(SpsWebSocketClient client) {

@ -100,7 +100,7 @@ public class SpsSyncWebSocket {
// value.session.getBasicRemote().sendText(s); // value.session.getBasicRemote().sendText(s);
// } // }
// 推送结束符 // 推送结束符
value.session.getBasicRemote().sendText("#end#"); // value.session.getBasicRemote().sendText("#end#");
} }
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
@ -128,7 +128,7 @@ public class SpsSyncWebSocket {
// value.session.getBasicRemote().sendText(s); // value.session.getBasicRemote().sendText(s);
// } // }
// 推送结束符 // 推送结束符
value.session.getBasicRemote().sendText("#end#"); // value.session.getBasicRemote().sendText("#end#");
} }
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();

Loading…
Cancel
Save