Put and Get data asynchronously

You have mail!

Sending and receiving data

The next step is to send and receive for this to work we need to get the atKeys file containing the cryptographic keys and login or onboard to the atServer. From there we can put data and get data as if a database was local to us but in fact data is remote on the data owners atServer.

This is achieved by every data element having an owner (the sending atSign) and a receiving atSign, behind the scenes the atSDK encrypts the data and sends it on to the atServer for delivery. All we need to do is a simple:

await atClient.put(sharedRecordID, message, putRequestOptions: pro);

of course we also have to setup the atClient object and onboard but that is all in the at_key_put.dart file for you. so let's send some data.

Running the program without arguments brings up this help, most is self explanatory.

dart run .\bin\at_key_put.dart                                                                
    --help                        Usage instructions
-a, --atsign (mandatory)          This client's atSign
-n, --namespace (mandatory)       Namespace
-k, --key-file                    Your atSign's atKeys file if not in ~/.atsign/keys/
-c, --cram-secret                 atSign's cram secret
-h, --home-dir                    home directory
-s, --storage-dir                 directory for this client's local storage files
-d, --root-domain                 Root Domain
                                  (defaults to "root.atsign.org")
-v, --verbose                     More logging
    --never-sync                  Do not run sync
-o, --other-atsign (mandatory)    The atSign we want to communicate with
-m, --message (mandatory)         The message we want to send
Invalid argument(s): Option other-atsign is mandatory.

*Note here we are using the atSigns activated in the previous section just substitute your own atSigns.

 dart run .\bin\at_key_put.dart -a "@energetic22" -n "atsign" -o "@7capricorn" -m "hello world" 
 
 dart run .\bin\at_key_get.dart -a "@7capricorn" -n "atsign" -o "@energetic22"

The -nnamespace is lefthand side of the atRecord so in this case the full atRecord would be @7capricorn:message.atsign@energetic22 and you see this in the results too. Experiment yourself!

You may also notice yourself that the first time you fail to get the message. This is because we specified in the metadata that the TTL is 60000 millisecond or 1 minute. Try again as you see in the above image and you should get your message too.

    ..metadata = (Metadata()
      ..ttl = 60000 // expire after 60 seconds
      ..ttr = -1); // allow recipient to keep a cached copy

The code is worth taking a look at the code as it less than 70 lines but allows data to transferred from a device anywhere to a device anywhere, and the data is fully encrypted.

The data in this example is "store and forward", which is ideal for many use cases but sometimes we need near real time data and that's what we cover next.

Last updated

© 2023 Atsign