Thales' cellular IoT products business is now part of Telit Cinterion, find out more.

You are here

TCP socket connection hangs on BGS5 | Telit Cinterion IoT Developer Community

February 2, 2015 - 1:15pm, 4296 views

Hello,
  I have esperienced throuble using socket connection on BGS5.
My software hangs on any read or write operation when the TCP connection drops, for example, because signal stregth of GSM is too low.

Is there something wrong with my software?
Has anyone else experienced this same problem?

The firmware version used is:
ati1
Cinterion
BGS5
REVISION 01.100
A-REVISION 00.000.07

and the software I used for the test is the following:
 
package NetDemo;

import javax.microedition.midlet.*;
import java.io.*;
import javax.microedition.io.*;

public class NetDemo extends MIDlet implements Runnable {
   
    static String destHost = "x.x.x.x";
    static String destPort = "7";
    static String connProfile = "bearer_type=gprs;access_point=ibox.tim.it;username=;password=";

    SocketConnection    sc  = null;
    InputStream         is  = null;
    OutputStream        os  = null;

    boolean                 Esci=false;
   
    /**
    * NetDemo - default constructor
    */
    public NetDemo()
    {
        System.out.println("NetDemo: Constructor");
    }

    /**
    * startApp()
    */
    public void startApp() throws MIDletStateChangeException
    { 
      
        System.out.println("NetDemo: startApp");

        try
        {      
            long t0=System.currentTimeMillis();
           
            String openParm = "socket://" + destHost + ":" + destPort+ ";" + connProfile;           
            System.out.println("NetDemo: Connector open: " + openParm);            
            sc = (SocketConnection) Connector.open(openParm);
            sc.setSocketOption(SocketConnection.LINGER,30);

            is = sc.openInputStream();
            os = sc.openOutputStream();

            // Lancia il Thread di ricezione
            Thread rxThread = new Thread(this);
            rxThread.start();
                       
            System.out.println("Attesa ...");            
           
            // Attende fine thread
            while(rxThread.isAlive()) {
                Thread.sleep(5000);
                System.out.println((System.currentTimeMillis()-t0)/1000+" secondi passati");
            }
           
            System.out.println("Chiudo ...");            

            Esci=true;
           
            /* Close all */
            is.close();
            os.close();
            sc.close();
           
        }
        catch (Exception e)
        {
            System.out.println("NetDemo: " + e.getMessage());
        }   
       
        System.out.println("Fine app");

        destroyApp(true);
    }

    /**
    * pauseApp()
    */
    public void pauseApp() {
        System.out.println("NetDemo: pauseApp()");
    }

    /**
    * destroyApp()
    *
    * This is important.  It closes the app's RecordStore
    * @param cond true if this is an unconditional destroy
    *             false if it is not
    *             currently ignored and treated as true
    */
    public void destroyApp(boolean cond) {
        System.out.println("NetDemo: destroyApp(" + cond + ")");

        notifyDestroyed();
    }

    /**
     *  Thread ricezione
     */
    public void run() {

        byte[] buffer = new byte[256];
        int n=0;
       
        System.out.println("Inizio thread ricezione");
        try {
       
            os.write("Hello world".getBytes());
            System.out.println("Attesa risposta...");
           
            while ((n = is.read(buffer))>0)
            {
                String rx = new String(buffer,0,n);
                System.out.println("Ricevuto:"+rx);
            }
           
        } catch (IOException e) {
            System.out.println(e.getMessage());
        }
       
        System.out.println("Fine thread ricezione");
    }
}