EHS6 - How to resolv server socket name using Java? | Telit Cinterion IoT Developer Community
October 13, 2016 - 11:24pm, 3048 views
Hello,
I tried to connect to a server socket via Java using SocketConnection class but the module was not able to resolve the server name, see code and exception below. Is there a way that the module could resolve server name in EHS6 using Java?
Thanks
try {
irisSocket = (SocketConnection) Connector.open("socket://www.teste.com.br:48765;bearer_type=gprs;access_point=apn.com.br;username...", Connector.READ_WRITE, true);
in = irisSocket.openInputStream();
out = irisSocket.openOutputStream();
} catch (IOException e) {
e.printStackTrace();
}
javax.microedition.io.ConnectionNotFoundException: Could not resolve hostname
- com.sun.midp.io.j2me.socket.Protocol.connect(), bci=89
- com.sun.midp.io.j2me.socket.Protocol.open(), bci=154
- com.sun.midp.io.j2me.socket.Protocol.openPrim(), bci=4
- javax.microedition.io.Connector.open(), bci=47
- cas.fenix.serverconnector.appia.AppiaConnector.connect(AppiaConnector.java:107)
- cas.fenix.serverconnector.appia.AppiaConnector.handle(AppiaConnector.java:307)
- cas.fenix.serverconnector.appia.AppiaConnector.run(AppiaConnector.java:261)
Hello,
This is a question about DNS. I can't see your full connection string - you can configure the DNS address there. Or if you don't you can get the address from the network. But this depends on the network configuration. Usually you should get it.
You can use the code below to display the bearer state and DNS servers:
BearerControl.addListenerEx(new BearerControlListenerEx() {
public void stateChanged(String APN, int state, int PdpErrCause) {
try {
System.out.println("APN: " + APN);
System.out.println("BEARER state change: " + state);
System.out.println("BEARER ADDR: "
+ BearerControl.GetBearerV4Addr(APN));
System.out.println("BEARER DNS1: "
+ BearerControl.GetBearerV4Dns1(APN));
System.out.println("BEARER DNS2: "
+ BearerControl.GetBearerV4Dns2(APN));
} catch (IOException e) {
e.printStackTrace();
}
}
});
Regards,
Bartłomiej
Hello,
Sorry, the connection string was hidden somehow, please see:
socket: // www.teste.com.br: 48765; bearer_type=gprs; access_point=apn.com.br; username=user; password=pass
How to configure the dns in the connection string?
Also, I got DNS1=0.0.0.0 and DNS2=0.0.0.0 after executing the code that you provided.
Thanks!
How about the bearer address? Do you get any address? All the parameters are described in the API for SocketConnection class. You just need to add the address of some DNS server to the connection string, for example "socket: // www.teste.com.br: 48765; bearer_type=gprs; access_point=apn.com.br; username=user; password=pass;dns=8.8.8.8".
Hello,
Now I am able to get DNS server from the network. So it works even when I am not using "dns" in the connection string. However, if I take the sim card away after connected to server, the module is not able to connect again. In this case, I got this exception:
java.io.IOException: Profile could not be activated
- com.sun.midp.io.j2me.socket.Protocol.open(), bci=149
- com.sun.midp.io.j2me.socket.Protocol.openPrim(), bci=4
- javax.microedition.io.Connector.open(), bci=47
I am able to connect again only when I restart the module. What should I do for connecting again without restarting the module?
When it is connected, I can see the network parameters, see:
Address: 100.66.76.131
State: 3
DNS 1: 8.8.8.8
DNS 2: 200.222.0.34
Thank you!
Hello,
When the SIM card is removed during the operation the network connection is always lost. So you should have a good reason to do that. This is a standard exception that can occur when the module cannot connect to data carrier. It can happen when the APN is not correctly configured. So your application should be prepared for that.
If in your solution the SIM card will be removed and inserted during the operation you should use the CCIN line of the SIM interface. It is needed to detect that the SIM card has been inserted again.
Generally it should be possible to reconnect after the SIM card is inserted and the module registers to the network. What exactly is the problem in your case: no SID detected, no network registration, the application is not able to establish the connection to remote host...
Regards,
Bartłomiej