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
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
. 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.
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
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. Files on the server that are outside the base directory may not be synced.
When connecting over Bluetooth, no Internet connection is required, but the two devices must be in close physical proximity.
The function returns a logical value of 1 (true) if the synchronization was successful and 0 (false) otherwise.
// start a peer-to-peer Bluetooth server with the application directory as the file root path
// start a peer-to-peer Bluetooth server with the application parent directory as the file root path