PL62-W as a server TCP/IP | Telit Cinterion IoT Developer Community
February 14, 2023 - 10:39pm, 206 views
I'm developing a server with the PLS62-W module, but I'm having difficulties connecting to this device. I'm using a variable IP, so whenever the firmware runs the IP will be modified. When I try to connect to any IP provided by the APN, nothing happens (the server remains waiting for the client to connect). My question is, is there any other parameter that I am failing to configure? Here is the developed firmware:
package threads;
import java.io.*;
import java.util.*;
import javax.microedition.io.*;
import sockets.SocketRoteamento2;
public class ThreadSocketListener extends Thread {
public static boolean loopTimers = true;
private static ThreadSocketListener instance = null;
// StreamConnectionNotifier serverConnection;
//int port = 47002;
DataInputStream is;
DataInputStream os;
ServerSocketConnection serverConnection;
SocketConnection socketconnection;
// Field descriptor #5 B
public static final byte DELAY = 0;
// Field descriptor #5 B
public static final byte LINGER = 1;
// Field descriptor #5 B
public static final byte KEEPALIVE = 2;
// Field descriptor #5 B
public static final byte RCVBUF = 3;
// Field descriptor #5 B
public static final byte SNDBUF = 4;
public ThreadSocketListener getInstance() {
if (instance == null) {
instance = new ThreadSocketListener();
instance.init();
}
return instance;
}
private void init() {
}
public void run() {
try {
ServerSocketConnection serverConnection = (ServerSocketConnection) Connector.open("socket://" + ":50018");
while (true) {
System.out.println("Waiting for connection on port: 50018");
SocketConnection socketconnection = (SocketConnection) serverConnection.acceptAndOpen();
System.out.println("Connection to established.");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// Get the input stream of the connection.
DataInputStream is = socketconnection.openDataInputStream();
// Get the output stream of the connection.
DataOutputStream os = socketconnection.openDataOutputStream();
// Read the input data.
// String result = is.readUTF();
String resultado = is.readUTF();
System.out.println(resultado);
String result = "Helloword";
// Echo the data back to the sender.
os.write(result.getBytes());
serverConnection.close();
socketconnection.close();
is.close();
os.close();
}
} catch (IOException e) {
System.out.println(e.toString() + " Exception");
try {
serverConnection.close();
socketconnection.close();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
}
Best regards,
Pedro.
Hello Pedro,
First of all you need a public IP address.
Are you sure that you are getting the public IP address on the module?
You may still need to check it with your operator because even if it is a dynamic public IP they might still be blocking the incoming connections for instance.
If you have the private IP address and try to connect from the client on the same device there's still no guarantee because the operator may be blocking such connections.
So, the best way would be to request proper service from your operator.
Best regards,
Bartłomiej