Opening a bearer connection before Connector.open() | Telit Cinterion IoT Developer Community
December 16, 2016 - 12:59pm, 3802 views
Hello,
To communicate via TCP/UDP sockets, it is needed to open a connection in Java.
Connector.open() method opens a TCP/UDP connection for this purpose. Module can be a server or a client.
There are optional parameters related to connection. These are bearer_type, access_point, username, password etc. With Connector.open method all these parameters can be used. In this situation, 2 operations will be done at one action.
1. Connect internet via apn (define and activate a pdp context)
2. Open a socket using previosly created connection.
Is it possible to make first operation alone using Java API?
In at interface, at+cgdcont defines a pdp context and at+cgact command activates a pdp context. After these 2 commands, module connects to internet. But any socket opened at that moment.
There is a class in com.cinterion.io named BearerControl. It has a method hangUp which can provide closing of a bearer connection but I couldn't see any method that opens a bearer connection.
Is it supported in Java API?
Best Regards,
Hello,
This is not possible for Java, BearerControl also cannot do that. The connection is established automatically when it's needed. There is only an option to define the profile with AT^SJNET command and then there is no need to specify the APN, user, password etc. in the connection string.
Is there any particular reason why you would like to have it that way?
Regards,
Bartłomiej
Hello Bartlomiej,
Thanks for the answer.
I have a sequence diagram which other party sends commands to module and module gives responses to it. One command is "join network". According to the sequence, module should join the gprs network and should return its IP address as a response to that command. I want to get IP address of module assigned by network before opening a TCP/UDP connection.
Is there a workaround solution that you can offer for this situation?
Best Regards,
Ergün.
Hello Bartlomiej,
Is it possible for BGS5 to have more than one IP address using different apn configurations and communicating over them successfully at the same time?
Suppose you open 3 ServerSocketConnection each of them has different apn configurations with default parameters. In this situation module can get 3 different IP address. 3 client can connect to each SocketServer and communicate.
Is it possible?
Best Regards,
Hello,
I think that you could force the network connection by opening some dummy connection for a while just to read the IP - the ServerSocketConnection would be good because the module would not need to connect to any host and send any data.
You just need to remember that the network may disconnect the bearer if the connection will be idle for a long time.
Regards,
Bartłomiej
Hello Bartlomiej,
Thanks for the answer.
Is it possible setting timeout value for connection to stay up though there is no connection.
I will open a ServerSocketConnection and it will stay up until set time exceeds. In this time there won't be any socket connection from any host.
I set SJNET timeout parameter to 30 but it didn't drop after 30 seconds while no connection established.
Hello,
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. So if the server socket is open to listen for incoming connections it will not be terminated. The value 0 means no timeout at all.
But I rather meant the disconnection initiated by the network in my previous post. I depends on the network configuration but all networks drop the idle connections after some time of inactivity (it may be many hours) to free the resources.
Best regards,
Bartłomiej
Hello Bartlomiej,
I understand that from your explanations:
1. If I open a SocketServer and don't close it, its close decision given by network i.e. gsm operator, not by module. The survive time can be hours or short depending on the network.
2. If I don't open a SocketServer but open a client socket connection to a server and close socket after data communication. Network connection will drop after waiting for timeout value specified in SJNET. Right?
One more question, in 1 case, If I open a SocketServer and after some time close it, is sjnet timeout value effective for connection close as in case 2?
I will test those scenarios but before it, I want to learn the expected behaviours.
Best Regards,
Ergün.
Hello,
1. If you open the server socket and leave it open it will remain open (will not be closed by the defined timeout). The network can drop the connection if there will be no communication for some network-dependent time.
2. The connection should be dropped by the module after closing the last socket (client or server) and timeout expiration.
If you are not interested in closing the network connection you should always set timeout 0. Generally I thought that you are just interested in opening the bearer, getting the IP and then connection to some other host without waiting for a significant time that could result in the disconnection caused by the network.
Regards,
Bartłomiej
Ok Bartlomiej,
Thank you very much.
Best Regards,