Push Examples

Contents Hide

  

Example 1. Push data to remote client (full push)

    var server = "10.0.0.111" ;

    var pusher = new Push(server, 8090) ;

    var vect = new Vector() ;

    var startIndex ;

    var maxRecordCount = 10 ;

    var base = 0 ;

    try

    {

        ScriptSession.logInfo("Creating data for CUSTOMER table ...") ;

 

        rs = new RecordSet("CUSTOMER") ;

        vectFieldInfo = new Vector() ;

        vectFieldInfo.add(new FieldInfo("ID", FieldInfo.INTEGER, true, 0, false)) ;

        vectFieldInfo.add(new FieldInfo("NAME", FieldInfo.STRING, false, 100, true)) ;

        vectFieldInfo.add(new FieldInfo("ADDRESS", FieldInfo.STRING, false, 100, true)) ;

        rs.setFieldInfo(vectFieldInfo) ;

 

        // Get the variable for starting point

        startIndex = ScriptSession.getVariable("StartIndex") ;

        if (startIndex == null)

        {

            base = 0 ;

        }

        else

        {

            base = startIndex.intValue() ;

        }

        for (i=base; i<(base+maxRecordCount); i++)

        {

            record = new Record() ;

            record.add(new Integer(i)) ; // ID

            record.add("COMPANY " + i) ; // NAME

            record.add("ADDRESS " + i) ; // ADDRESS

            rs.addRecord(record) ;

        }

        vect.add(rs) ;

        ScriptSession.logInfo("Sending data to " + server + " ...") ;

        pusher.sendData(vect) ;

        ScriptSession.logInfo("Data sent successfully.") ;

 

        // Move to next block

        ScriptSession.persistVariable("StartIndex", new Integer(i)) ;

    }

    catch(error)

    {

        ScriptSession.logInfo("Error sending data : " + error) ;

    }

Note:

Example 2. Force remote device to synchronise (semi push)

    var server = "10.0.0.111" ;

    var pusher = new Push(server, 8090) ;

    try

    {

        // Forcing remote client to sync

        ScriptSession.logInfo("Forcing remote client to sync ...") ;

        pusher.forceRemoteSync("SyncRuleGetTable4") ;

        ScriptSession.logInfo("Forced remote client to sync successfully.") ;

    }

    catch(error)

    {

        ScriptSession.logInfo("Error forcing remote device to sync : " + error) ;

    }

Note: