Need simple example of device to server (my own computer) interaction

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Suleymanov

I am trying to understand the basics of sending data to a server and bringing data back to a device.

Can you please show me an example how I can send a simple numeric value to my server computer, store it in already created .txt document, then call it back to the device?

Thank you for your time!

:bust_in_silhouette: Reply From: MxtApps

You should use something like that:

func _ready():
         var xhr = HTTPRequest.new();

        xhr.connect("request_completed", self, "OnRequestCompleted");

          var body = {"num": 5}
          var status = xhr.request("127.0.0.1/numfile", [], true, HTTPClient.METHOD_POST, body)

if status != OK:
    push_error("Something went wrong :(")


func OnRequestCompleted(result, response_code, headers, body):
         print(body.get_string_from_utf8())

You need to create a num_file in your server and write it, for example, in PHP.

I hope this will be useful for you.
MxtApps :slight_smile: