Is it possible to call functions from uplink, provided the app runs under anvil-app-server?

Hi,

What I’m trying to do:
What I try is to call functions of an uplinked code, resident at the same machine with the anvil-app-server and Git_cloned app, from client.

What I’ve tried and what’s not working:
The calls work when the app operates in browser, but when I run it via the anvil-app-server, the uplink functions can’t be found by the client (NoServerFunctionError: No server function matching “xxxx_xxxx” has been registered). Checked the cases for this error in the forum, but did not find solution
I don’t know the basic principles of the app server and I guess the client is restricted to call server_modules only. I hope I’m wrong and will appreciate any advice how to resolve or work around this issue.

# This is the form of illustrative example:
class Form1(Form1Template):
  def __init__(self, **properties):    
    self.init_components(**properties)
    self.label_1.text = "Calling the server func hello()"
    r = anvil.server.call("hello")
    self.label_2.text = f"Received r = {r}"

  def button_1_click(self, **event_args):    
    r = anvil.server.call("hello")
    self.label_3.text += f"{r} " + ' '` 

# This is an uplinked server func:
@anvil.server.callable
def hello():
  print("Uplink REACHED")
  return("I'm HERE")

anvil.server.connect("server_75MALOC3BBRCRAYQGCXPOXHP-CSIPMK67RPV3EZ3Y") 

while True:
  if keyboard.is_pressed('p'):
    print("Main is ending ... ")
    time.sleep(0.1)
    break
sys.exit(0)

Did you add the uplink-key to your config or as a param when launching the app-server? That should sort it.

Thanks for the fast response, James!

This was the result:
Calling function ‘hello’ for app ‘Utest’ (ID server-osS83uiyshdxjg==)
Worker terminated for IDs set() (return code None)
[ERROR anvil.app-server.run] Error report from client code:
NoServerFunctionError: No server function matching “hello” has been registered
Traceback:
app/Utest/Form1/init.py:13

Okay, so from memory you have to add uplink-key “yourkey” to the command line when you launch the app-server and, also, you have to add the wss:// for your app to the method of your uplink connect in your local code…

EDIT:

Perhaps covered here? [App Server] Inject a user at deployment time - #3

1 Like

Actually, I started the server by: anvil-app-server --app Utest --uplink-key server_75MALOC3BBRCRAYQGCXPOXHP-CSIPMK67RPV3EZ3Y. Is that what you suggest?
Regarding the wss:// I’ve never done this. Would you, please, recommend a link to read about how to

Thanks

Hey James, Thank you very much, indeed!
The test started successfully and I do appreciate your quick support!

Well done! App-server can be tricky sometimes.

I’m a bit late to this one, but you might want to have a look at our Amoni tool which attempts to make life simpler when using the app server.

Have been meaning to ask you about this …does it simplify the adding an email service bit, which has nearly driven me mad?

There’s nothing specific to do with email in amoni, I’m afraid.

Was worth a shout! Obliged, Owen.

Thank you very much for this advuce, Owen! I will certainly try the Amoni. By the way, may I run couple of app servers on Windows 10 machine?

Sure. With amoni, they’re just docker containers, so you can run as many as you like. If they run simultaneously, you’d have to adjust the ports they listen on, but that’s about it.

1 Like

Thanks Owen! Appreciated!