"(SocketConnection) Connector.open(openParm);" freezes . | Telit Cinterion IoT Developer Community
October 28, 2021 - 4:52pm, 1198 views
Dear,
I am using an MTX-T device
Cinterion EHS6
My program opens the socket in a TimerTask and normally works fine. It opens the socket, sends data frames to server, closes the socket, ends the run procedure and until the next activation of the TimerTask.
This is how it works normally, but sometimes it freezes when opening the socket, without throwing an exception.
This is the portion of the code that opens the socket.
public boolean GSMConnect() {
try {
String openParm = "socket://" + destHost + ":" + destPort+ ";" + connProfile;
System.out.print("GSMCom.GSMConnect: " + openParm);
synchronized(gsmLock){
System.out.print(" Conn 1 ");
sc = (SocketConnection) Connector.open(openParm);
System.out.print(" Conn 2 ");
is = sc.openInputStream();
System.out.println(" Conn 3 ");
os = sc.openOutputStream();
}
return true;
} catch (Exception e) { e.printStackTrace();
System.out.println("GSMCom.GSMConnect Error: " + e.getMessage());
return false;
}
}
How can I prevent the program from freezing in this procedure (Connector.open)?
If I can't stop it from freezing, could I force close the TimerTask and open a new one?
Best regards.
Hello,
For how long can it freeze? Is the network connection active at that time?
I think that you could try to close such a connection from another thread.
BR,
Bartłomiej
I think the thread that opens the port can freeze forever (I have waited more than 8 hours). It does not return from Connector.open and it does not finish executing.
What would be the proper procedure to close the connection from another thread? Would I have to relaunch the timer Task or when closing the port, would the run procedure be activated again? I will continue testing, but it takes so long to fail that it can become eternal.
Thank you Bartłomiej
regards
Hello,
Normally it should return in a reasonable time. Please check network registration and signal quality. Maybe you'll observe some relation.
I believe that closing the socket connection should trigger an exception from open() method which will be caught by your catch block. So it should not prevent the Timer from scheduling the next execution.
BR,
Bartłomiej