|
@@ -4,10 +4,7 @@ package com.game.business.websocket;
|
|
import com.game.business.config.GameTwoConfig;
|
|
import com.game.business.config.GameTwoConfig;
|
|
import com.game.business.config.SpringContextSetting;
|
|
import com.game.business.config.SpringContextSetting;
|
|
import com.game.business.util.Common;
|
|
import com.game.business.util.Common;
|
|
-import com.game.business.websocket.client.GameFourClient;
|
|
|
|
-import com.game.business.websocket.client.GameOneClient;
|
|
|
|
-import com.game.business.websocket.client.GameThreesClient;
|
|
|
|
-import com.game.business.websocket.client.GameTwoClient;
|
|
|
|
|
|
+import com.game.business.websocket.client.*;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
|
import javax.websocket.ContainerProvider;
|
|
import javax.websocket.ContainerProvider;
|
|
@@ -31,50 +28,55 @@ public class WebSocketConnent {
|
|
}
|
|
}
|
|
|
|
|
|
public void connect() throws Exception{
|
|
public void connect() throws Exception{
|
|
- /* while (true){
|
|
|
|
- try {
|
|
|
|
- System.out.println("正在" + (this.WS_CONNENT_NUM == 0 ? "" : ("第" + this.WS_CONNENT_NUM + "次")) + "连接WebSocket[" + this.WS_URL_NAME + "]......");
|
|
|
|
-
|
|
|
|
- if(StringUtils.isBlank(WS_NOW_URL)){
|
|
|
|
- WS_NOW_URL = WS_URL;
|
|
|
|
- }else{
|
|
|
|
- if(WS_NOW_URL.equals(WS_URL)){
|
|
|
|
- WS_NOW_URL = WS_REMARK_URL;
|
|
|
|
- }else{
|
|
|
|
- WS_NOW_URL = WS_URL;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if(Common.GANME_ONE_NAME.equals(this.WS_URL_NAME)){
|
|
|
|
- GameOneClient client = SpringContextSetting.getBean(GameOneClient.class);
|
|
|
|
- ContainerProvider.getWebSocketContainer().connectToServer(client, new URI(this.WS_NOW_URL));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if(Common.GANME_TWO_NAME.equals(this.WS_URL_NAME)){
|
|
|
|
- GameTwoClient client = SpringContextSetting.getBean(GameTwoClient.class);
|
|
|
|
- ContainerProvider.getWebSocketContainer().connectToServer(client, new URI(this.WS_NOW_URL));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if(Common.GAME_THREES_NAME.equals(this.WS_URL_NAME)){
|
|
|
|
- GameThreesClient client = SpringContextSetting.getBean(GameThreesClient.class);
|
|
|
|
- ContainerProvider.getWebSocketContainer().connectToServer(client, new URI(this.WS_NOW_URL));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if(Common.GAME_FOUR_NAME.equals(this.WS_URL_NAME)){
|
|
|
|
- GameFourClient client = SpringContextSetting.getBean(GameFourClient.class);
|
|
|
|
- ContainerProvider.getWebSocketContainer().connectToServer(client, new URI(this.WS_NOW_URL));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- System.out.println(this.WS_URL_NAME + " 已成功连接Websocket[" + this.WS_NOW_URL + "]");
|
|
|
|
- this.WS_CONNENT_NUM = 0;
|
|
|
|
- break;
|
|
|
|
- }catch (Exception e){
|
|
|
|
- if(this.WS_CONNENT_MAX_NUM > this.WS_CONNENT_NUM){
|
|
|
|
- this.WS_CONNENT_NUM ++;
|
|
|
|
- }
|
|
|
|
- System.out.println("连接[" + this.WS_URL_NAME + "]异常," + this.WS_CONNENT_NUM + "秒后尝试重新连接:" + e.getMessage());
|
|
|
|
- Thread.sleep(this.WS_CONNENT_NUM * 1000);
|
|
|
|
- }
|
|
|
|
- }*/
|
|
|
|
|
|
+// while (true){
|
|
|
|
+// try {
|
|
|
|
+// System.out.println("正在" + (this.WS_CONNENT_NUM == 0 ? "" : ("第" + this.WS_CONNENT_NUM + "次")) + "连接WebSocket[" + this.WS_URL_NAME + "]......");
|
|
|
|
+//
|
|
|
|
+// if(StringUtils.isBlank(WS_NOW_URL)){
|
|
|
|
+// WS_NOW_URL = WS_URL;
|
|
|
|
+// }else{
|
|
|
|
+// if(WS_NOW_URL.equals(WS_URL)){
|
|
|
|
+// WS_NOW_URL = WS_REMARK_URL;
|
|
|
|
+// }else{
|
|
|
|
+// WS_NOW_URL = WS_URL;
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// if(Common.GANME_ONE_NAME.equals(this.WS_URL_NAME)){
|
|
|
|
+// GameOneClient client = SpringContextSetting.getBean(GameOneClient.class);
|
|
|
|
+// ContainerProvider.getWebSocketContainer().connectToServer(client, new URI(this.WS_NOW_URL));
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// if(Common.GANME_TWO_NAME.equals(this.WS_URL_NAME)){
|
|
|
|
+// GameTwoClient client = SpringContextSetting.getBean(GameTwoClient.class);
|
|
|
|
+// ContainerProvider.getWebSocketContainer().connectToServer(client, new URI(this.WS_NOW_URL));
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// if(Common.GAME_THREES_NAME.equals(this.WS_URL_NAME)){
|
|
|
|
+// GameThreesClient client = SpringContextSetting.getBean(GameThreesClient.class);
|
|
|
|
+// ContainerProvider.getWebSocketContainer().connectToServer(client, new URI(this.WS_NOW_URL));
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// if(Common.GAME_FOUR_NAME.equals(this.WS_URL_NAME)){
|
|
|
|
+// GameFourClient client = SpringContextSetting.getBean(GameFourClient.class);
|
|
|
|
+// ContainerProvider.getWebSocketContainer().connectToServer(client, new URI(this.WS_NOW_URL));
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// if(Common.GAME_FIVE_NAME.equals(this.WS_URL_NAME)){
|
|
|
|
+// GameFiveClient client = SpringContextSetting.getBean(GameFiveClient.class);
|
|
|
|
+// ContainerProvider.getWebSocketContainer().connectToServer(client, new URI(this.WS_NOW_URL));
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// System.out.println(this.WS_URL_NAME + " 已成功连接Websocket[" + this.WS_NOW_URL + "]");
|
|
|
|
+// this.WS_CONNENT_NUM = 0;
|
|
|
|
+// break;
|
|
|
|
+// }catch (Exception e){
|
|
|
|
+// if(this.WS_CONNENT_MAX_NUM > this.WS_CONNENT_NUM){
|
|
|
|
+// this.WS_CONNENT_NUM ++;
|
|
|
|
+// }
|
|
|
|
+// System.out.println("连接[" + this.WS_URL_NAME + "]异常," + this.WS_CONNENT_NUM + "秒后尝试重新连接:" + e.getMessage());
|
|
|
|
+// Thread.sleep(this.WS_CONNENT_NUM * 1000);
|
|
|
|
+// }
|
|
|
|
+// }
|
|
}
|
|
}
|
|
}
|
|
}
|