January 19, 2017 - 12:14pm, 12691 views
How to check state of a SocketConnection with Java API?
After a SocketConnection opened, if other party closes the socket or if it drops due to network conditions how to be aware of that? Is there a notification to catch?
Actually I don't want to use a lot of sockets open. In my scenario, maximum 3 sockets can be alive.
But I will use ServerSocketConnection to accept client connections and need to know how many connections module can handle, if I accept all connection requests with acceptAndOpen method.
I made a test yesterday. I always listened a port with ServerSocketConnection and accepted all requests. I tried socket connection from my pc using a tcp client program, module accepted 14 connections. 15. request rejected by module automatically though my program accepts.
When using at services maximum 10 service profile exists. If I set one profile for socket server, remaining 9 profile could be set as socket client.
It seems that you have found the limits. I have also run the similar test in Java and it was possible to accept and exchange data on 15 connections. So with the server socket that would make 16.
Hello Mr. Bartlomiej,
I am having the same sought of problem. I am developing a client which also looks for whether internet connection is down or the remote side break the connection.
In my scenario, I connect to the server and start exchanging data. For testing purposes that everything works fine , after getting into exchanging data state between client and Server I took out the Sim card and writing to the socket throws an IO exception (expected behaviour). But if instead of taking out the Sim card , I take out the GSM antenna cable an IO Exception is not thrown until I reconnect the GSM antenna cable ( Strange behaviour ). Afterwards I try to reconnect but it says profile can't be activated ( thats also very strange ). Any hints regarding that.
Disconnecting the antenna does not necessarily need to cause the network disconnection - if the signal is strong the communication might still be working. Does reconnection of the antenna always cause the exception?
It should be possible to establish another connection after reconnecting the antenna and network registration. Do you check the wireless network registration status before making the socket connection attempt? Is it possible to connect in another attempt?
Yes, I have checked everything. When I try to make a first Connection attempt using Connector.open() with credentials everything works fine , but suppose if I want to make a re-connection using Connection.open() after 30 s ( it fails by saying profile can't be activated.... I have checked the APN and registration status of the sim card card and they are fine).
So, I would generalize this error as making an attempt to call Connector.open() for the second time causes profile not activated error even though registration status and APN are fine.
I have changed the reconnection timings. Previously I was reconnecting after 30s, but I have changed it to one minute now (and it seems to work). It looks for me that it takes atleast 30 s to put the bearer status to Closing state and then Down state. This can be viewed using the BearerControlListener class.
If you open a connection, then close it and try to open again in 30 seconds (or open another connection in 30 seconds without closing the previous one) there is always an exception?
Probably it takes some time to close and reopen the bearer but I wouldn't expect the exception. How about the network quality?
If you would try to open another connection in let's say 2 seconds from closing the previous one then probably the bearer would not be closed at all. It's good that you are using the BearerControlListener - you can see the bearer state then.
So as I understand if you wait long enough after closing the last connection you never get the "profile can't be activated" exception.
There's one more thing to consider here - there is a timeout parameter that you can configure in the connection string or AT^SJNET command. This parameter specifies the Java network idle timeout, which is the number of seconds to wait before the network connection is terminated automatically after having closed the last socket on this connection. The value 0 means no timeout at all and the default is 30 seconds. That would explain your observations with 30 seconds delay in closing the bearer.
Thanks for your answer.
-Regarding the timeout you metioned I am not giving any timeout values. So, it means if I don't explicitly specifiy the timeout value in Connector.open(), the default value of timeout = 30s is taken into consideration. Thats why reconnection time of 60s works (or may be value greater than 30s). Am I right on that ?
As you have already mentioned in one of your previous posts in another thread that a call to Connector.open() first dials with the specified credentials :
socketConnection = (SocketConnection)Connector.open(addressAndPort);
So, calling socketConnection.close() breaks the connection with the server to whom I am connected to as well as it breaks the Connection to the network ( Internet ), which can be seen from BearerControlListener class. Am I right on that ?
Yes, you are correct about the timeout.
Yes, Connector.open() opens the bearer if it's not already open.
The bearer is closed when the timeout expires after closing the last socket on the bearer. If you have opened more sockets and some of them are still open the bearer will not be closed until you close the last one.
Of course the data connection could also be closed by the network.
I am experiencing something very strange behaviour with the below mentioned scenario:
I start the EHS5 without the sim card and give an AT command (AT+CREG?) returns me 0,0 ( which means not registered not searching obvious behaviour). But (AT+CSQ) returns me 14,99 to 16.99 which in terms of signal strength is good. I would be expecting value of 99,99 which is unknown or detectable behaviour. For reference : http://m2msupport.net/m2msupport/atcsq-signal-quality/ .
Is this the expected behaviour ?
In case there is no network there should be 99,99 returned.
It can happen that after removing the SIM card or network deregistration during the operation the CSQ will still be returning the last valid value but I wouldn't expect and I haven't seen other value then 99 just after start with no SIM card.
© 2013-2023 Thales DIS AIS Deutschland GmbH - a Telit Cinterion Company