private int localPort = -1;
private int remotePort = -1;
private Socket controlSocket = null;
-
+
public BaseCommunicator(DeviceInfo device) {
this.device = device;
}
// port foward
localPort = CommunicatorUtils.getFreePort();
result = CommunicatorUtils.forward(device.getIDevice(), localPort, remotePort);
- if (!result.isSuccess()) {
- Logger.warning("Failed to port fowarding, remove this device : "
- + device.getIDevice().getSerialNumber());
- return result;
- }
+ if (!result.isSuccess()) {
+ Logger.warning("Failed to port fowarding, remove this device : "
+ + device.getIDevice().getSerialNumber());
+ return result;
+ }
+ }
+
+ try {
+ Thread.sleep(100);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
}
// connect control socket
+
result = createControlSocket();
+
if (!result.isSuccess()) {
- Logger.warning(result.toString());
- result = new DAResult(ErrorCode.ERR_CONTROL_SOCKET_CREATION_FAIL);
- return result;
+ // if connect Failed retry 'createControlSocket'
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ result = createControlSocket();
+
+ if (!result.isSuccess()) {
+ Logger.warning(result.toString());
+ result = new DAResult(ErrorCode.ERR_CONTROL_SOCKET_CREATION_FAIL);
+ return result;
+ }
+
}
+
// get protocol version
protocolVersion = checkVersion();
if (protocolVersion == null || protocolVersion.isEmpty()) {
} finally {
// unforward port (forwarded port is not necessary anymore)
if (localPort > 0 && remotePort > 0) {
- CommunicatorUtils.unforward(device.getIDevice(), localPort, remotePort);
+
+ Thread UnforwardThread = new Thread(new Runnable() {
+ public void run() {
+ CommunicatorUtils.unforward(device.getIDevice(), localPort, remotePort);
+ }
+ });
+
+ UnforwardThread.start();
}
if (!result.isSuccess()) {
if (null != device && isOnline(device)) {
try {
device.createForward(local, remote);
- Thread.sleep(AnalyzerConstants.SOCKET_FORWARD_INTERVAL);
} catch (TimeoutException e) {
Logger.exception(e);
result = new DAResult(ErrorCode.ERR_EXCEPTION_OCCURRED);
Logger.exception(e);
result = new DAResult(ErrorCode.ERR_EXCEPTION_OCCURRED);
result.setDetailMessage(e.getMessage());
- } catch (InterruptedException e) {
- Logger.exception(e);
- result = new DAResult(ErrorCode.ERR_EXCEPTION_OCCURRED);
- result.setDetailMessage(e.getMessage());
} catch (NullPointerException e) {
Logger.exception(e);
result = new DAResult(ErrorCode.ERR_EXCEPTION_OCCURRED);