• <GetStart>
  • CSPro User's Guide
    • The CSPro System
    • Data Dictionary Module
    • The CSPro Language
    • Data Entry Module
    • Batch Editing Applications
    • Tabulation Applications
    • Data Sources
    • CSPro Statements and Functions
      • Statement Format Symbols
      • Alphabetical List of Functions and Statements
      • List of Reserved Words
      • Deprecated Features
      • Declaration Statements
      • Symbol Functions
      • Item Functions
      • Array Object
      • Audio Object
      • Barcode and QR Codes
      • Case Object
      • Document Object
      • File Object
      • Freq Object
      • Geometry Object
      • HashMap Object
      • Image Object
      • List Object
      • Map Object
      • Path
      • Pff Object
      • SystemApp Object
      • ValueSet Object
      • Program Control Statements
      • Assignment Statements
      • Data Entry Statements and Functions
      • Batch Edit Statements
      • Numeric Functions
      • String Functions
      • Multiple Occurrence Functions
      • General Functions
      • Date and Time Functions
      • External File Functions
      • Synchronization Functions
        • SyncConnect Function
        • SyncConnect Function (CSWeb)
        • SyncConnect Function (Bluetooth)
        • SyncConnect Function (Dropbox)
        • SyncConnect Function (LocalDropbox)
        • SyncConnect Function (LocalFiles)
        • SyncConnect Function (FTP)
        • SyncServer Function
        • SyncDisconnect Function
        • SyncData Function
        • SyncFile Function
        • SyncMessage Function
        • SyncParadata Function
        • SyncApp Function
        • SyncTime Function
        • GetBluetoothName Function
        • SetBluetoothName Function
    • Templated Reporting System
    • HTML and JavaScript Integration
    • Action Invoker
    • Appendix
  • <CSEntry>
  • <CSBatch>
  • <CSTab>
  • <DataViewer>
  • <TextView>
  • <TblView>
  • <CSFreq>
  • <CSDeploy>
  • <CSPack>
  • <CSDiff>
  • <CSConcat>
  • <Excel2CSPro>
  • <CSExport>
  • <CSIndex>
  • <CSReFmt>
  • <CSSort>
  • <ParadataConcat>
  • <ParadataViewer>
  • <CSCode>
  • <CSDocument>
  • <CSView>
  • <CSWeb>

SyncServer Function

Format
b = syncserver(Bluetoothʃ, file_root_pathʅ);
Description
The syncserver function runs a local server that allows peer-to-peer synchronization between two devices via Bluetooth, without needing an Internet connection. The function waits for a connection from another device (a client) made when the client calls syncconnect to start a Bluetooth synchronization. Once the two devices are connected, the client device calls syncdata and syncfile to copy data and/or files to and from the server. Finally, the client device calls syncdisconnect to end the session.
The server in a peer-to-peer synchronization is passive. It does not call syncdata or syncfile. It simply responds to requests initiated from the client. The Bluetooth server runs until either the client successfully connects and disconnects or the operator cancels the synchronization.
The syncserver function displays a dialog to the operator indicating that it is waiting for a client device to connect. During this time, no other logic on the server is executed. Once a connection is made, the dialog displays the progress of the synchronization. When the client disconnects by calling syncdisconnect, the dialog is removed and syncserver returns. If no connection is made, the operator can use the cancel button on the dialog to cause syncserver to return and continue executing any logic that follows. The server only allows connections while the syncserver function is running, so the server must call syncserver before the client device calls syncconnect.
The first argument must be the keyword Bluetooth. The second argument, file_root_path, is an optional string expression of the path to use as the base directory from which to transfer files when the client calls syncfile. The remote path specified in the call to syncfile is appended to this base directory to determine the full path of files on the server. In other words, "/" in a syncfile call from the client refers to the file_root_path directory on the server. For example, if file_root_path is "C:\MyApp\MyFiles" and the client calls syncfile(GET,"/Images/image.jpg"), then the file image.jpg will be read from the directory C:\MyApp\MyFiles\Images\ on the server. If no file_root_path is specified, the application directory is used. The rules that dictate which files can be synced on the server differ depending on the operating system. On Android files inside the csentry directory can be synced by default. To sync outside the csentry directory use file_root_path to specify a path outside the csentry directory. On Windows any file can be synced.
When connecting over Bluetooth, no Internet connection is required, but the two devices must be in close physical proximity.
Return Value
The function returns a logical value of 1 (true) if the synchronization was successful and 0 (false) otherwise.
Example 1
// start a peer-to-peer Bluetooth server with the application directory as the file root path
syncserver(Bluetooth);
Example 2
// start a peer-to-peer Bluetooth server with the application parent directory as the file root path
syncserver(Bluetooth, "..");
See also: Synchronization Overview, SyncConnect Function, SyncData Function, SyncDisconnect Function, SyncFile Function, SyncMessage Function, SetBluetoothName Function