• <GetStart>
  • CSPro User's Guide
    • The CSPro System
    • Data Dictionary Module
    • The CSPro Language
    • Data Entry Module
    • Batch Editing Applications
    • Tabulation Applications
    • Data Sources
    • Synchronization
    • CSPro Statements and Functions
      • Statement Format Symbols
      • Alphabetical List of Functions and Statements
      • List of Reserved Words
      • Deprecated Features
      • Declaration Statements
      • Numeric Values
      • String Values
      • 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
      • StringWriter 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
        • SyncServer Function
        • SyncDisconnect Function
        • SyncData Function
        • SyncFile Function
        • SyncMessage Function
        • SyncParadata Function
        • SyncApp Function
        • SyncTime Function
        • GetBluetoothName Function
        • SetBluetoothName Function
    • Text Templates
    • Templated Reporting System
    • HTML, Markdown, and JavaScript Integration
    • Action Invoker
    • Appendix
  • <CSEntry>
  • <CSBatch>
  • <CSTab>
  • <DataManager>
  • <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 using Bluetooth. No Internet connection is required, but the two devices must be in close physical proximity because Bluetooth is a short-range wireless technology.
The function waits for a connection from another device, the "client," made when the client calls syncconnect to start Bluetooth synchronization. You can use the setbluetoothname function if you want to set the server device's Bluetooth name that the client sees when trying to make a connection.
Once the two devices are connected, the client calls functions such as syncdata and syncfile to copy data and/or files to and from the server. Finally, the client calls syncdisconnect to end the session.
The server in a peer-to-peer synchronization is passive. It does not call any synchronization functions. It simply responds to requests initiated by the client. The Bluetooth server runs until either the client successfully disconnects (after connecting), or the operator cancels the synchronization.
If the client's synchronization logic depends on data from the server, such data can be passed between devices by having the client send a message using syncmessage or Sync.sendMessage, which the server responds to using OnSyncMessage.
The syncserver function displays a dialog to the operator indicating that it is waiting for a client 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 dialog's cancel button 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 what files can be synced on the server differ depending on the operating system. On Android, only files within the csentry directory can be synced. On Windows, any file can be synced.
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, Bluetooth Synchronization Service, SetBluetoothName Function, Synchronization Messages